material/Beiträge/DDI-Vortrag 2/Source/sources/bubblesort.pas

27 lines
No EOL
657 B
ObjectPascal

program BubbleSort;
{$APPTYPE CONSOLE}
uses
SysUtils;
Procedure BubbleSort(var a: array of Integer, var size: Integer);
var i,j,temp: integer;
begin
for i:=size downto 1 do
for j:=1 to i-1 do
if a[i]>a[j] then
begin
temp:=a[i];
a[i]:=a[j];
a[j]:=temp;
end;
end;
begin
var A: array [1..10] of Integer:
A[1] := 7; A[2] := 9; A[3] := 1; A[4] := 2; A[5] := 3;
A[6] := 6; A[7] := 4; A[8] := 5; A[9] := 8; A[10] := 0;
BubbleSort(A,10);
for i:=1 to 10 do
write(A[i], " ")
writeln("");
end.