unit ViewFormMain;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TListType =
array of Integer;
TMainFormView =
class( TForm )
Unsorted_ListBox : TListBox;
Unsorted_GroupBox : TGroupBox;
Sorted_GroupBox : TGroupBox;
Sorted_ListBox : TListBox;
DoWork_Button: TButton;
procedure DoWork_ButtonClick( Sender : TObject );
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
MainFormView : TMainFormView;
implementation
{$R *.dfm}
procedure Swap(
var Left, Right : Integer );
var
LTemp : Integer;
begin
LTemp := Left;
Left := Right;
Right := LTemp;
end;
procedure SortList(
var AList : TListType );
var
LIdx, LCompareIdx : Integer;
begin
for LIdx := low( AList )
to high( AList ) - 1
do
begin
for LCompareIdx := high( AList )
downto LIdx
do
begin
if AList[LIdx] > AList[LCompareIdx]
then
Swap( AList[LIdx], AList[LCompareIdx] );
end;
end;
end;
procedure FillRandomList(
var AList : TListType; ACount : Integer );
var
LIdx : Integer;
begin
SetLength( AList, ACount );
for LIdx := low( AList )
to high( AList )
do
begin
AList[LIdx] := Random( 100 );
end;
end;
procedure ShowListInListBox(
const AList : TListType; AListBox : TListBox );
var
LIdx : Integer;
begin
AListBox.Items.BeginUpdate;
try
AListBox.Clear;
for LIdx := low( AList )
to high( AList )
do
begin
AListBox.Items.Add( IntToStr( AList[LIdx] ) );
end;
finally
AListBox.Items.EndUpdate;
end;
end;
procedure TMainFormView.DoWork_ButtonClick( Sender : TObject );
var
LList : TListType;
begin
FillRandomList( LList, 20 );
ShowListInListBox( LList, Unsorted_ListBox );
SortList( LList );
ShowListInListBox( LList, Sorted_ListBox );
end;
end.