📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,math,dateutils,strutils;
type
TForm1 = class(TForm)
Label2: TLabel;
Edit2: TEdit;
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
Button2: TButton;
CheckBox1: TCheckBox;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
DataValue:array of integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
vv:integer;
begin
setlength(datavalue,strtoint(edit2.Text ));
listbox1.clear;
for vv:=0 to strtoint(edit2.Text )-1 do begin
randomize;
datavalue[vv]:= random(strtoint(edit2.Text ));
if CheckBox1.Checked then listbox1.Items.Add(inttostr(datavalue[vv]));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
IntMaxValue: Integer;
intTotals: Integer;
BoolVarT: Boolean;
CT:double;
SYSP:int64;{系统频率}
CalTime1,CalTime2:int64;{计时始末时间}
begin
boolvart := true;
intTotals := strtoint(edit2.Text )-1;
ListBox2.Items.Clear;
QueryPerformanceFrequency(sysp);
QueryPerformanceCounter(caltime1);
while BOOLVART do
begin
boolvart := false;
for i:=0 to intTotals do begin
if datavalue[i]>datavalue[i+1] then begin
IntMaxValue := datavalue[i+1];
datavalue[i+1] := datavalue[i];
datavalue[i] := IntMaxValue;
boolvart := true;
end;
end;
intTotals := intTotals-1;
end;
if CheckBox1.Checked then
for i:=0 to strtoint(edit2.Text )-1 do
ListBox2.Items.Add(IntToStr(datavalue[i]));
QueryPerformanceCounter(caltime2);
//ct:=(caltime2-caltime1)/sysp;//取得计时时间,单位秒(s)
ct:=(caltime2-caltime1)/sysp*1000;//取得计时时间,单位毫秒(ms)
// ct:=(caltime2-caltime1)/sysp*1000000;//取得计时时间,单位微秒
label1.Caption :=formatfloat('#0.000',ct)+'毫秒' ;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -