Q
qrj
Unregistered / Unconfirmed
GUEST, unregistred user!
我是用2个Listbox和两个按纽,第一个按纽控制listbox1,第二个按纽用快速排序实现对listbox1里的10随机数按从小到大排列,并在listbox2中输出结果,希望大家帮帮忙啊!!!谢谢!!!
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to 9 do
begin
ListBox1.Items.Add(IntToStr(Random(10)));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
low,high,m,temp:integer;
a:Array[0..9] of integer;
begin
for m:=0 to 9 do
begin
a[m]:=StrToInt(ListBox1.Items[m+1]);
end;
low:=0;
High:=9;
temp:=a[0];
while low<high do
begin
while (low<high) And (a[high]>=temp) do
begin
high:=high-1;
a[low]:=a[high];
end;
while (low<high) And (a[low]<=temp) do
begin
low:=low+1;
a[high]:=a[low];
end;
end;
a[low]:=a[0];
for m:=0 to 9 do
begin
ListBox2.Items.Add(IntToStr(a[m]));
end;
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to 9 do
begin
ListBox1.Items.Add(IntToStr(Random(10)));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
low,high,m,temp:integer;
a:Array[0..9] of integer;
begin
for m:=0 to 9 do
begin
a[m]:=StrToInt(ListBox1.Items[m+1]);
end;
low:=0;
High:=9;
temp:=a[0];
while low<high do
begin
while (low<high) And (a[high]>=temp) do
begin
high:=high-1;
a[low]:=a[high];
end;
while (low<high) And (a[low]<=temp) do
begin
low:=low+1;
a[high]:=a[low];
end;
end;
a[low]:=a[0];
for m:=0 to 9 do
begin
ListBox2.Items.Add(IntToStr(a[m]));
end;
end;
end.