unit BubbleSortForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Menus;
type
IntegerArray=array of Integer;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button2: TButton;
Function ToString(NumberArray:IntegerArray;Lens:Integer):String;
private
{ Private declarations }
Function SelectedSort(NumberArray:IntegerArray;Lens:Integer):IntegerArray;
public
{ Public declarations }
procedure Button2_Sort(Sender: TObject);
end;
var
Form1: TForm1;
NumberCount:Integer;
{SortArray:array of Integer;}
SortArray:IntegerArray;
implementation
{$R *.dfm}
function TForm1.ToString(NumberArray:IntegerArray;Lens:Integer):String;
var
Count:Integer;
Str:String;
begin
Str:='';
FOR Count:=0 TO lens-1 DO
BEGIN
Str:=Str+IntToStr(NumberArray[Count]);
END;
Result:=Str;
end;
function TForm1.SelectedSort(NumberArray:IntegerArray;Lens:Integer):IntegerArray;
var
SortedNumberArray:IntegerArray;
Count:Integer;
I:Integer;
J:Integer;
Temp:Integer;
begin
System.SetLength(SortedNumberArray,Lens);
// Assgin array items value
FOR Count:=0 TO Lens DO
BEGIN
SortedNumberArray:=NumberArray;
END;
FOR I:=0 TO Lens-1 DO
BEGIN
FOR J:=I+1 TO Lens-1 DO
BEGIN
IF SortedNumberArray[I]>SortedNumberArray[J] THEN
BEGIN
Temp:=SortedNumberArray[I];
SortedNumberArray[I]:=SortedNumberArray[J];
SortedNumberArray[J]:=Temp;
END;
END;
END;
RichEdit2.Text:=ToString(SortedNumberArray,Lens);
end;
procedure TForm1.Button2_Sort(Sender: TObject);
var
Count:Integer;
begin
System.SetLength(SortArray,NumberCount);
FOR Count:=0 TO NumberCount-1 DO
BEGIN
SortArray[Count]:=StrToInt(RichEdit1.Lines[Count]);
END;
SelectedSort(SortArray,10);
end;
end.