Als je wilt weten hoe de vork in de steel zit, zou ik een array gebruiken met b.v. een bubblesort. Dan zie je wat er gebeurt,
Code:
{
Bubble Sort is very! inefficient but a good way to understand
more difficult sorting algorithms such as insertion sort.
Bubble Sort works by repeatedly scanning the array,
checking adjacent pairs of values to see if they
are in the proper order.
Whenever a pair of values is found to be out of order,
they are interchanged and done is set to false,
to indicate the array must be scanned again.
This procedure will end when the array
scanned and all adjacent values are in their proper sorted
order. }
procedure BubbleSort(Items: TStrings);
var
done: boolean;
i, n: integer;
Dummy: string;
begin
n := Items.Count;
repeat
done := true;
for i := 0 to n - 2 do
begin
if Items[i] > Items[i + 1] then
begin
Dummy := Items[i];
Items[i] := Items[i + 1];
Items[i + 1] := Dummy;
done := false;
end;
end;
until done;
end;
Bookmarks