In einer Demo von DELPHI sieht der Code so aus:
Delphi-Quellcode:
procedure TSortThread.VisualSwap(A, B, I, J: Integer);
begin
FA := A;
FB := B;
FI := I;
FJ := J;
Synchronize(DoVisualSwap);
end;
procedure TBubbleSort.Sort(
var A:
array of Integer);
var
I, J, T: Integer;
begin
for I := High(A)
downto Low(A)
do
for J := Low(A)
to High(A) - 1
do
if A[J] > A[J + 1]
then
begin
VisualSwap(A[J], A[J + 1], J, J + 1);
T := A[J];
A[J] := A[J + 1];
A[J + 1] := T;
if Terminated
then Exit;
end;
end;