unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TArray =
array[1..20]
of integer;
type
TForm1 =
class(TForm)
SpeedButton1: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private-Deklarationen }
procedure FillArray(
var Tab: TArray);
procedure Swap(
var Zahl1, Zahl2: integer);
procedure QuickSort(
var Tab: TArray; HighIndex: integer);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Tab: TArray;
implementation
{$R *.dfm}
procedure TForm1.FillArray(
var Tab: TArray);
var i: integer;
begin
for i := 1
to Length(Tab)
do
Tab[i] := random(101);
//0 - 100
end;
procedure TForm1.Swap(
var Zahl1, Zahl2: integer);
var h: integer;
begin
h := Zahl1;
Zahl1 := Zahl2;
Zahl2 := h;
end;
procedure TForm1.QuickSort(
var Tab: TArray; HighIndex: integer);
procedure Sort(links, rechts: integer);
var i, j, x: integer;
begin
i := links;
j := rechts;
x := Tab[(links + rechts)
div 2];
repeat
while Tab[i] < x
do inc(i);
while Tab[j] > x
do dec(j);
if i <= j
then
begin
Swap(Tab[i], Tab[j]);
inc(i);
dec(j);
end;
until i > j;
if links < j
then Sort(links, j);
if i < rechts
then Sort(i, rechts);
end;
begin
Sort(1, HighIndex);
end;
procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
randomize;
FillArray(Tab);;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var i: integer;
begin
QuickSort(Tab, Length(Tab));
end;
end.