unit Uselect;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Zufallszahl: TButton;
Selectionsort: TButton;
MemoZufallszahl: TMemo;
MemoSelect: TMemo;
procedure SelectionsortClick(Sender: TObject);
procedure ZufallszahlClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
A: array [1..20] of integer;
implementation
{$R *.lfm}
procedure AFuellen(var insArray: array of integer;Min, Max: integer);
var i:integer;
begin
for i:= Low(insArray) to High (insArray) do
begin
insArray[i]:= Random(Max-Min+1)+Min;
end;
end;
procedure ArraySortieren( var k:array of integer);
Var
i, j : LongInt;
Temp, Min: LongInt;
Begin
For i := Low(k) To High(k) Do
Begin
Min := i;
For j := i+1 To High(k) Do
If k[j] < k[Min] Then
Min := j;
Temp := k[Min];
k[Min] := k[i];
k[i] := Temp;
End;
End;
end.
procedure InsMemo(const insArray: array of integer; AMemo:TMemo);
var
x:integer;
begin
AMemo.Lines.BeginUpdate;
try
AMemo.Clear;
for x:= Low(insArray) to High (insArray) do
begin
AMemo.Lines.Add(IntToStr(insArray[x]));
end;
finally
AMemo.Lines.EndUpdate;
end;
end;
{ TForm1 }
procedure TForm1.ZufallszahlButtonClick(Sender: TObject);
begin
AFuellen(A,1,100);
InsMemo(A,MemoZufallszahl);
end;
procedure TForm1.SelectionsortClick(Sender: TObject);
begin
SortArray(A);
InsMemo(A,MemoSelect);
end;
end.