delphi 一组数据,按由大到小进行排序,并输出最大值与最小值


本文整理自网络,侵删。

 

622,132,35,403,303,312,235,119,642,858,329,33,154,49,43,561,842,203,915,567,905,609,161,317,574,688,819,310,209,88,909,211,719,503,149,268,868,592,230,98,984,871,518,636,343,694,846,793,112,755,45,849,524,638,326,764,836,364,202,152,850,778,698,78,409,807,472,541,923,139,983,34,190,116,39,814,48,656,507,555,890,556,979,1000,281,272,118,60,751,122,261,274,75,52,204,380,880,800,527,155,685,198,514,258,292,331,876,682,477,777,232,359,802,438,944,99,859,709,841,577,63,603,539,782,351,355,349,607,967,68,625,50,87,563,239,95,336,657,710,998,265,86,282,129,320,73,749,441,989,17,708,23,992,36,67,616,602,437,307,648,354,585,51,318,502,644,739,540

 

将以上数组由大到小进行排序,并输出最大值与最小值

procedure TForm1.SpeedButton1Click(Sender: TObject);

Var

  i,cID,MaxID,MinID:Integer;

  cText:String;

  bNext:Boolean;

  cStr:Array of integer;

  cStrList:TStringList;

begin

  cText:='';  Memo2.Clear;

  cStrList:=TStringList.Create;

  for i := 0 to Memo1.Lines.Count-1 do

    cText:=cText+Trim(Memo1.Lines[i]);

  bNext:=True;

  while bNext do

    begin

      cStrList.Add(Copy(cText,1,Pos(',',cText)-1));

      cText:=Copy(cText,Pos(',',cText)+1,Length(cText));

      if cText=',' then Break;

      bNext:=pos(',',cText)>0;

    end;

  // Memo2.Lines:=cStrList; exit;

   SetLength(cStr,cStrList.Count);

   for I := 0 to cStrList.Count-1 do

      cStr[i]:=STRTOINT(cSTrList[i]);

  Tarray.Sort<Integer>(cSTR);

  for I := Low(cSTR) to High(cSTR)  do

    Memo2.Lines.Add(INTTOSTR(cSTR[i]));

   Edit1.Text:=INTTOSTR(cSTR[high(cSTR)]);

   Edit2.Text:=INTTOSTR(cSTR[0]);

 

end;

 

来源:https://www.cnblogs.com/wuxi15/archive/2013/01/14/2859264.html

相关阅读 >>

Delphi如何自动重启程序

Delphi fdconnection1.gettablenames 查看所有表包含用户表和系统表

Delphi winapi: setvolumelabel - 设置磁盘卷标

Delphi 修改快捷方式

Delphi添加任务栏右键菜单

Delphi 关于 array of const

Delphi 暴力搜索api

Delphi10.3模拟读取百度网页,并读取相关头部信息

Delphi判断操作系统是否win10

我的Delphi开发经验谈

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...