Maopao排序
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DBCtrls; type queue = array[1..200] of integer; TForm1 = class(TForm) btn1: TButton; lbl1: TLabel; edt1: TEdit; btn2: TButton; btn3: TButton; dblst1: TDBListBox; dbtxt1: TDBText; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); procedure btn3Click(Sender: TObject); private { Private declarations } public procedure sort1(var queue1: queue; n: integer); procedure swap(var x, y: integer); { Public declarations } end; var Form1: TForm1; i: integer; dataarray: queue; implementation {$R *.dfm} procedure TForm1.sort1(var queue1: queue; n: integer); var k, j: integer; begin for k := 1 to n - 1 do begin for j := 1 to n - k do if queue1[j] < queue1[j + 1] then begin swap(queue1[j], queue1[j+1]); end; end end; procedure TForm1.swap(var x, y: integer); var temp:integer; begin temp := x; x := y; y := temp; end; procedure TForm1.btn1Click(Sender: TObject); var j: integer; begin dbtxt1.Caption := '排序后: '; sort1(dataarray, i); for j := 1 to i do dbtxt1.Caption := dbtxt1.Caption + ' ' + IntToStr(dataarray[j]); i := 0; end; procedure TForm1.btn2Click(Sender: TObject); begin i := i + 1; dataarray[i] := StrToInt(edt1.Text); dblst1.Items.Add(edt1.Text); edt1.Text := ''; edt1.SetFocus; end; procedure TForm1.btn3Click(Sender: TObject); begin Close; end; end.