빠른정렬(QuickSort) 입니다.^^
<!--CodeS-->
const
data : array[0..7] of integer = (123,34,189,56,150,12,9,240);
procedure TForm1.Button1Click(Sender: TObject);
begin
sort(0, 7);
end;
procedure TForm1.Sort(l, r: Integer);
var
i, j, x, y: integer;
begin
i := l;
j := r;
x := data[(l+r) DIV 2];
repeat
while data[i] < x do i := i + 1;
while x < data[j] do j := j - 1;
if i <= j then
begin
y := data[i];
data[i] := data[j];
data[j] := y;
i := i + 1;
j := j - 1;
end;
until i > j;
if i < r then Sort(i, r);
if l < j then Sort(l, j);
end;
<!--CodeE-->
빠른정렬(QuickSort) 입니다.^^
<!--CodeS-->
const
data : array[0..7] of integer = (123,34,189,56,150,12,9,240);
procedure TForm1.Button1Click(Sender: TObject);
begin
sort(0, 7);
end;
procedure TForm1.Sort(l, r: Integer);
var
i, j, x, y: integer;
begin
i := l;
j := r;
x := data[(l+r) DIV 2];
repeat
while data[i] < x do i := i + 1;
while x < data[j] do j := j - 1;
if i <= j then
begin
y := data[i];
data[i] := data[j];
data[j] := y;
i := i + 1;
j := j - 1;
end;
until i > j;
if i < r then Sort(i, r);
if l < j then Sort(l, j);
end;
<!--CodeE-->