文本框中输入一些数字字符,用逗号隔开,怎样用delphi实现从大到小排序

比如文本框中输入23,12,56,34,71
点击按钮后在另一个文本框中输出12,23,34,56,71
只是打个比方,数字是运行后随便输的。。。

第1个回答  2011-07-23
//用记事本写的,可能有些bug

//快速排序
Procedure qsort(l,r:longint);
var i,j,x,y:longint;
  begin
  i:=l;j:=r;x:=a[random(r-l)+l];//随机化即可
    Repeat
    while a<x do inc(i);
    while a[j]>x do dec(j);
    if i<=j then
      begin
      y:=a;
      a:=a[j];
      a[j]:=y;
      inc(i);
      dec(j);
    end;
  until i>j;
  if i<r then qsort(i,r);
  if j>l then qsort(l,j);
end;

begin

S:=edit1.text;

top:=0;now:='';

for i:=1 to length(s) do
if s[i]=',' then begin inc(top);val(now,a[top],code);now:='';end else now:=now+s[i];
//如果最后还有一个数,将这个数纳入栈
if now<>'' then begin inc(top);val(now,a[top],code);end;
//排序
qsort(1,top);
s:='';
for i:=1 to top do
begin
str(a[i],now);
s:=s+now+',';
end;
//除去最后一个','
s:=copy(s,1,length(s)-1);
edit2.text:=s;

end;追问

a是哪来的啊?

追答

a是一个整型数组

第2个回答  2011-08-05
Procedure qsort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;j:=r;x:=a[random(r-l)+l];//随机化即可
Repeat
while a<x do inc(i);
while a[j]>x do dec(j);
if i<=j then
begin
y:=adf;
a:=a[j];
a[j]:=y;
inc(i);
dec(j);
end;本回答被提问者采纳
第3个回答  2011-07-24
转变成整数,存到数组中,排序后,再转成字符型,显示出来
第4个回答  2011-07-22
使用递归的方法进行比较,将值大的放后边,值小的放前边.
最后输出.
第5个回答  2011-07-25
var tlist:tstringlist
i:integer;
begin
tlist.CommaText:=text1.text;
tlist.sort;
text2.text:=tlist.text;
end;