# Slowly sorting??

How can I sort this in a better faster way?
Can Delphi really do this faster?

SortingTime=3 min 26 sec

unit Unitsortingslowly;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
numbers1,numbers2,numbers3,numbers4:array[1..50000]of integer;
x1,x2,x3,x4:integer;
implementation

{\$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
j,i,a:integer;

begin
screen.Cursor:=crHourglass;

for a:=1 to 50000 do begin
numbers1[a]:=a+2;
numbers2[a]:=a+1;
numbers3[a]:=a+3;
numbers4[a]:=a;
end;

//sorting numbers
for j:=1 to 50000 do begin
for i:=1 to j do begin
if numbers1[j] > numbers1[i] then begin

x1:= numbers1[j];
numbers1[j] := numbers1[i];
numbers1[i]:=x1;

x2:= numbers2[j];
numbers2[j] := numbers2[i];
numbers2[i]:=x2;

x3:= numbers3[j];
numbers3[j] := numbers3[i];
numbers3[i]:=x3;

x4:= numbers4[j];
numbers4[j] := numbers4[i];
numbers4[i]:=x4;

end;// if
end;// i
end;// j

screen.Cursor:=crDefault;

for a:=1 to 50 do begin
listbox1.items.add (IntToStr(numbers1[a])+

' < numbers1 numbers2 > '+IntToStr(numbers2[a])+
' numbers3 > '+IntToStr(numbers3[a])+
' numbers4 > '+IntToStr(numbers4[a]));

end;

end;

end.

## Comments

• [b][red]This message was edited by Moderator at 2002-9-28 2:38:4[/red][/b][hr]
: How can I sort this in a better faster way?
: Can Delphi really do this faster?

: SortingTime=3 min 26 sec
: unit Unitsortingslowly;
: interface
: uses
: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
: Dialogs, StdCtrls;
: type
: TForm1 = class(TForm)
: ListBox1: TListBox;
: Button1: TButton;
: procedure Button1Click(Sender: TObject);
: procedure FormCreate(Sender: TObject);
: private
: { Private declarations }
: public
: { Public declarations }
: end;
:
: var
: Form1: TForm1;
: numbers1,numbers2,numbers3,numbers4:array[1..50000]of integer;
: x1,x2,x3,x4:integer;
: implementation
:
: {\$R *.dfm}
:
: procedure TForm1.Button1Click(Sender: TObject);
: var
: j,i,a:integer;
:
: begin
: screen.Cursor:=crHourglass;
:
: for a:=1 to 50000 do begin
: numbers1[a]:=a+2;
: numbers2[a]:=a+1;
: numbers3[a]:=a+3;
: numbers4[a]:=a;
: end;
:
: //sorting numbers
: for j:=1 to 50000 do begin
: for i:=1 to j do begin
: if numbers1[j] > numbers1[i] then begin
:
:
: x1:= numbers1[j];
: numbers1[j] := numbers1[i];
: numbers1[i]:=x1;
:
:
: x2:= numbers2[j];
: numbers2[j] := numbers2[i];
: numbers2[i]:=x2;
:
:
: x3:= numbers3[j];
: numbers3[j] := numbers3[i];
: numbers3[i]:=x3;
:
:
: x4:= numbers4[j];
: numbers4[j] := numbers4[i];
: numbers4[i]:=x4;
:
: end;// if
: end;// i
: end;// j
:
: screen.Cursor:=crDefault;
:
:
: for a:=1 to 50 do begin
: listbox1.items.add (IntToStr(numbers1[a])+
:
: ' < numbers1 numbers2 > '+IntToStr(numbers2[a])+
: ' numbers3 > '+IntToStr(numbers3[a])+
: ' numbers4 > '+IntToStr(numbers4[a]));
: end;
: end;
: end.

It Seems u use the Bubble Sort Algorithm, U better use Quick Sort Algorithm or other faster Algorithms, U Can find these, In Data Structure Book Refrences.
Reza

Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!