unit Mischsortieren;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 =
class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Liste:
array[1..100000]
of integer;
l: integer;
implementation
{$R *.dfm}
Procedure Mischsortieren1 (links,rechts: Integer);
var Endelinks, Anfangrechts:Integer;
Procedure Mischen1 (I,J:Integer);
var Z, K: Integer;
begin
if I<J
then
begin
if Liste[I]<=Liste[J]
then
begin
Mischen1(I+1,J);
end
else
begin
z:=Liste[J];
end;
For k:=J-1
to I
do
begin
Liste[K+1]:=Liste[k];
end;
Liste[I]:=Z;
if J<rechts
then
begin
Mischen1(I+1,J+1);
end;
end;
end;
begin
Endelinks:=round((links+rechts)/2);
Anfangrechts:=Endelinks+1;
if links<Endelinks
then
begin
Mischsortieren1(links,Endelinks);
end;
if Anfangrechts<rechts
then
begin
Mischsortieren1(Anfangrechts,rechts);
end;
Mischen1(links,Anfangrechts);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Randomize;
For l:= 1
to 100000
do
begin
Liste[l]:= Random(1000)+1;
stringgrid1.Cells[3,l]:=inttostr(Liste[l]);
end;
Mischsortieren1 (Liste[1],Liste[100000]);
For l:=1
to 100000
do
begin
stringgrid1.Cells[4,l]:=inttostr(Liste[l]);
end;
end;
end.