unit Sort;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Memo2: TMemo;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type ta=ARRay[1..100]
of integer;
var
Form1: TForm1;
n:integer;
a:
array[1..100]
of integer;
procedure bubble(
var a:ta; n:integer);
PROCEDURE Quicksort(
VAR a:ta; p,r:INTEGER);
Function Partition(
VAR a:ta; p,r:INTEGER):INTEGER;
procedure tausch(
var x,y:integer);
implementation
{$R *.dfm}
procedure tausch(
var x,y:integer);
var z:integer;
begin
x:=y;
Y:=z;
z:=x;
end;
Function Partition(
VAR a:ta; p,r:INTEGER):INTEGER;
VAR t,x,i,j:INTEGER;
BEGIN
x:=a[p];
i:=p-1;
j:=r+1;
WHILE i<j
DO
BEGIN
REPEAT
j:=j-1;
UNTIL a[j]<=x;
REPEAT
i:=i+1;
UNTIL x <= a[i];
IF i<j
THEN tausch(a[i],a[i])
(*Tausch der Elemente *)
ELSE RESULT:= j;
END;
END ;
PROCEDURE Quicksort(
VAR a:ta; p,r:INTEGER);
VAR q:INTEGER;
BEGIN
IF p<r
THEN
BEGIN
q:=Partition(a,p,r);
Quicksort(a,p,q);
Quicksort(a,q+1,r);
END;
END;
procedure bubble(
var a:ta; n:integer);
var x,i,j:integer;
begin
For j:=1
to n
do
For i:=1
to n-1
do
If a[i] > a[i+1]
then
begin
x:=a[i];
a[i]:=a[i+1];
a[i+1]:=x;
End;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i,n:integer;
begin
n:=memo1.lines.count;
for i:=1
to n
do
a[i]:=StrtoInt(memo1.Lines[i-1]);
end;
procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
memo1.clear;
memo2.clear;
for i:=1
to 10
do
memo1.lines.add(INtTOStr(random (20)))
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,n:integer;
begin
for i:=1
to n
do
quicksort(memo1.lines,n,x);
//DIE ZEILE HIER ISSES!!!
memo2.lines.add(INtToStr(a[i]));
end;
end.