unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) ListBox1: TListBox; ListBox2: TListBox; GroupBox1: TGroupBox; GroupBox2: TGroupBox; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; GroupBox3: TGroupBox; TrackBar1: TTrackBar; Label1: TLabel; Edit1: TEdit; Button5: TButton; GroupBox4: TGroupBox; Button6: TButton; Button7: TButton; Button8: TButton; Button9: TButton; Button10: TButton; Button11: TButton; Button12: TButton; Button13: TButton; Button14: TButton; Button15: TButton; Button16: TButton; Button17: TButton; Button18: TButton; Button19: TButton; procedure FormCreate(Sender: TObject); procedure TrackBar1Change(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button9Click(Sender: TObject); procedure Button10Click(Sender: TObject); procedure Button11Click(Sender: TObject); procedure Button12Click(Sender: TObject); procedure Button13Click(Sender: TObject); procedure Button14Click(Sender: TObject); procedure Button15Click(Sender: TObject); procedure Button16Click(Sender: TObject); procedure Button17Click(Sender: TObject); procedure Button18Click(Sender: TObject); procedure Button19Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; inputarray,sortarray: array of integer; arraylaenge: integer; implementation procedure fillinarray(); var i: integer; begin Form1.ListBox1.Clear; for i:=0 to arraylaenge-1 do begin Form1.ListBox1.Items.Add(FloattoStr(inputarray[i])); end; for i:=0 to arraylaenge-1 do begin sortarray[i]:=inputarray[i]; end; end; procedure quicksort(left,right:integer; direction: String); var i,j,help,pivot:integer; helparray:array of integer; begin if(direction='asc') then begin i:=left; j:=right; pivot:=sortarray[(left+right) div 2]; while i<=j do begin while sortarray[i]pivot do j:=j-1; if i<=j then begin if sortarray[i]>sortarray[j] then begin help:=sortarray[j]; sortarray[j]:=sortarray[i]; sortarray[i]:=help; end; i:=i+1; j:=j-1; end; end; if leftsortarray[j+1] then begin help:=sortarray[j]; sortarray[j]:=sortarray[j+1]; sortarray[j+1]:=help; end; end; end; ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button7Click(Sender: TObject); var i,j:integer;help:integer; begin for i:=0 to arraylaenge-1 do begin for j:=0 to arraylaenge-2 do begin if sortarray[j]0) and (sortarray[j-1] > b)) do begin sortarray[j]:=sortarray[j-1]; j:=j-1; end; sortarray[j]:=b; end; ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button9Click(Sender: TObject); var b,i,j:integer; begin for i:=0 to arraylaenge-1 do begin j:=i; b:=sortarray[i]; while ((j>0) and (sortarray[j-1] < b)) do begin sortarray[j]:=sortarray[j-1]; j:=j-1; end; sortarray[j]:=b; end; ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button10Click(Sender: TObject); var help,i,j:Integer; begin for i:=0 to arraylaenge-2 do begin for j:=i+1 to arraylaenge-1 do begin if sortarray[j]sortarray[i] then begin help:=sortarray[j]; sortarray[j]:=sortarray[i]; sortarray[i]:=help; end; end; end; ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button12Click(Sender: TObject); var i,j,help,min: integer; begin for i:=0 to arraylaenge-2 do begin min:=i; for j:=i+1 to arraylaenge-1 do begin if sortarray[j]i then begin help:=sortarray[min]; sortarray[min]:=sortarray[i]; sortarray[i]:=help; end; end; ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button13Click(Sender: TObject); var i,j,help,min: integer; begin for i:=0 to arraylaenge-2 do begin min:=i; for j:=i+1 to arraylaenge-1 do begin if sortarray[j]>sortarray[min] then min:=j; end; if min>i then begin help:=sortarray[min]; sortarray[min]:=sortarray[i]; sortarray[i]:=help; end; end; ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button14Click(Sender: TObject); const step: array[0..2] of byte = (5,3,1); var i,j,k,pos,help: integer; begin for k:=0 to 2 do begin for pos:=0 to step[k] do begin for i:=1 to ((arraylaenge-pos) div step[k]) do begin if sortarray[i*step[k]+pos]help) and (j>pos) do begin sortarray[j]:=sortarray[j-step[k]]; j:=j-step[k]; end; sortarray[j]:=help; end; end; end; end; ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button15Click(Sender: TObject); const step: array[0..2] of byte = (5,3,1); var i,j,k,pos,help: integer; begin for k:=0 to 2 do begin for pos:=0 to step[k] do begin for i:=1 to ((arraylaenge-pos) div step[k]) do begin if sortarray[i*step[k]+pos]>sortarray[(i-1)*step[k]+pos] then begin j:=i*step[k]+pos; help:=sortarray[j]; while (sortarray[j-step[k]]>help) and (j>pos) do begin sortarray[j]:=sortarray[j-step[k]]; j:=j-step[k]; end; sortarray[j]:=help; end; end; end; end; ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button16Click(Sender: TObject); var i:Integer; begin quicksort(0,arraylaenge-2,'asc'); ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button17Click(Sender: TObject); var i:Integer; begin quicksort(0,arraylaenge-2,'dsc'); ListBox2.Clear; for i:=0 to arraylaenge-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button18Click(Sender: TObject); var helparray1,helparray2:array of integer; i,j,k,min,max,diff:integer; begin min:=0; max:=0; for i:=0 to arraylaenge-1 do begin if sortarray[i]>max then max:=sortarray[i] else if sortarray[i]=1 then begin for j:=1 to helparray2[i] do begin sortarray[k]:=helparray1[i]; k:=k+1; end; end; end; ListBox2.Clear; for i:=0 to Length(sortarray)-1 do begin ListBox2.Items.Add(FloattoStr(sortarray[i])); end; end; procedure TForm1.Button19Click(Sender: TObject); var helparray1,helparray2:array of integer; i,j,k,min,max,diff:integer; begin min:=0; max:=0; for i:=0 to arraylaenge-1 do begin if sortarray[i]>max then max:=sortarray[i] else if sortarray[i]=1 then begin for j:=1 to helparray2[i] do begin sortarray[k]:=helparray1[i]; k:=k+1; end; end; end; ListBox2.Clear; for i:=1 to Length(sortarray) do begin ListBox2.Items.Add(FloattoStr(sortarray[Length(sortarray)-i])); end; end; end.