Quicksortarray: Procedure Var Var
Quicksortarray: Procedure Var Var
//This is a recursive quicksort that cuts the array down into smaller parts to be sorted each pass
var
movablePointer, immovablePointer, temporaryPointer : integer;
temporaryItem : string;
begin
immovablePointer := lowPos; //Set the immovable pointer to the lowest input part of the array
movablePointer := highPos; //Set the movable pointer to the highest input part of the array
while (movablePointer <> immovablePointer) do
begin
if(movablePointer > immovablePointer) then
//While the movable pointer is larger than the immovable, slowly move it towards the immovable,
checking each step if
//the value at that position is larger than the immovable's position.
begin
if(inputArray[movablePointer] < inputArray[immovablePointer]) then //If they are in the wrong
order, swap them!
begin
temporaryItem := inputArray[movablePointer]; //Exchange the values in the array with a
temporary value
inputArray[movablePointer] := inputArray[immovablePointer];
inputArray[immovablePointer] := temporaryItem;
temporaryPointer := movablePointer; //Exchange the positions to check
movablePointer := immovablePointer;
immovablePointer := temporaryPointer;
end
else
begin
dec(movablePointer); //Otherwise move the movable clsoer to the immovable
end;
end
else
begin
//Similar as above, but in the other direction
if(inputArray[movablePointer] > inputArray[immovablePointer]) then
begin
temporaryItem := inputArray[movablePointer];
inputArray[movablePointer] := inputArray[immovablePointer];
inputArray[immovablePointer] := temporaryItem;
temporaryPointer := movablePointer;
movablePointer := immovablePointer;
immovablePointer := temporaryPointer;
end
else
begin
inc(movablePointer);
end;
end;
//windows.beep(movablePointer * 40,20);
end;
//Now recursively check the lower and higher up parts of the array to sort
if(movablePointer > lowPos) then
quickSortArray(inputArray,lowPos,movablePointer-1);
if(movablePointer < highPos) then
quickSortArray(inputArray,movablePointer+1,highPos);
end;