unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Button3: TButton;
Button4: TButton;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private-Deklarationen}
public
{ Public-Deklarationen}
end;
var i,j,h,n:integer;
s:
string;
z:
array[1..10000]
of integer;
Form1: TForm1;
implementation
{$R *.DFM}
const nn=1000;
procedure TForm1.Button1Click(Sender: TObject);
var zeita,zeitb,zeitOP:integer;
begin
zeita:=gettickcount;
s:='
';
memo1.clear;
for i:=1
to nn
do
begin
z[i]:=random(100);
s:=s+IntToStr(z[i])+'
,';
end;
zeitb:=gettickcount;
zeitOP:=zeitb-zeita;
Label2.caption:=IntToStr(zeitOP);
memo1.lines.add(s);
j:=1;
n:=10;
end;
procedure TForm1.Button2Click(Sender: TObject);
var zeita,zeitb,zeitOP:integer;
begin
zeita:=gettickcount;
repeat
j:=j+1;
for i:=1
to j
do if z[j]<z[i]
then
begin
h:=z[i];
z[i]:=z[j];
z[j]:=h;
end;
until j=n;
zeitb:=gettickcount;
zeitOP:=zeitb-zeita;
Label1.caption:=IntToStr(zeitOP);
s:='
';
for i:=1
to n
do s:=s+IntToStr(z[i])+'
,';
memo1.lines.add(s);
end;
procedure Quicksort(
var A:
array of integer);
procedure Quick_Sort(
var A:
array of Integer; iLo, iHi: Integer) ;
var
Lo, Hi, Pivot, T: Integer;
begin
Lo := iLo;
Hi := iHi;
Pivot := A[(Lo + Hi)
div 2];
repeat
while A[Lo] < Pivot
do Inc(Lo) ;
while A[Hi] > Pivot
do Dec(Hi) ;
if Lo <= Hi
then
begin
T := A[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo) ;
Dec(Hi) ;
end;
until Lo > Hi;
if Hi > iLo
then Quick_Sort(A, iLo, Hi) ;
if Lo < iHi
then Quick_Sort(A, Lo, iHi) ;
end;
begin
Quick_Sort(A, Low(A), High(A)) ;
end;
procedure TForm1.Button3Click(Sender: TObject);
var i,n:integer;
begin
for i := 0
to nn
do z[i]:=random(10);
QuickSort(z);
s:='
';
for i:=1
to nn
do s:=s+IntToStr(z[i])+'
,';
memo1.lines.add(s);
end;
procedure TForm1.Button4Click(Sender: TObject);
var zeita,zeitb,zeitOP:integer;
begin
zeita:=gettickcount;
s:='
';
memo1.clear;
for i:=1
to nn
do
begin
z[i]:=random(100);
s:=s+IntToStr(z[i])+'
,';
end;
zeitb:=gettickcount;
zeitOP:=zeitb-zeita;
Label3.caption:=IntToStr(zeitOP);
memo1.lines.add(s);
end;
end.