unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons;
type
TForm1 =
class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Button3: TButton;
procedure QuickSort(A:
array of integer; iLo, iHi: Integer);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{----}
public
{----}
end;
var
Form1: TForm1;
arr:
array [0..10]
of integer;
a:
array of integer;
iLo, iHi: Integer;
implementation
{$R *.dfm}
procedure TForm1.QuickSort(A:
array of integer; iLo, iHi: Integer);
var
Lo, Hi, Mid, T: Integer;
begin
Lo := iLo;
Hi := iHi;
Mid := A[(Lo + Hi)
div 2];
ShowMessage(IntToStr(Mid)+'
'+IntToStr(Hi)+'
'+IntToStr(Lo));
repeat
while A[Lo] < Mid
do Inc(Lo);
while A[Hi] > Mid
do Dec(Hi);
if Lo <= Hi
then
begin
T := A[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo
then QuickSort(A, iLo, Hi);
if Lo < iHi
then QuickSort(A, Lo, iHi);
end;
procedure TForm1.Button2Click(Sender: TObject);
var I: Integer;
begin
QuickSort(arr,Low(arr),High(arr));
for I:=Low(arr)
to High(arr)
do Listbox2.Items.Add(IntToStr(arr[I]));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
Randomize;
for I:=Low(arr)
to High(arr)
do
arr[I]:=Random(100);
for I:=Low(arr)
to High(arr)
do
Listbox1.Items.Add(IntToStr(arr[I]));
end;