Quick sort en pascal
Aqui les dejo el codigo de el quick sort para pascal, este codigo yo lo hice
PROGRAM quicksortin;
{ MoYo }
USES CRT;
CONST
elementsinuse = 10; { number of elements in the array }
TYPE
thearraytype = array [1..elementsinuse] OF INTEGER; { the array type }
VAR
thearray : thearraytype; { the array declared }
first, last : integer; { the lower and upper value}
temp : integer;
{**********************************************************}
PROCEDURE swap (VAR x, y : integer); { procedure to switch the numbers }
VAR
temp : integer;
BEGIN
temp := x;
x := y;
y := temp;
END;
{**********************************************************}
{ the procedure to get the data or the quick sort }
PROCEDURE qsort(VAR thearray : thearraytype; first : integer;
last : integer);
VAR
right, left : integer;
midpoint : integer;
BEGIN { qsort }
midpoint := thearray[(first + last) div 2]; { get the midpoint }
right := first; { set left to lower }
left := last; { set right to upper }
REPEAT { begin repeat }
WHILE (thearray[right] <>
right := right + 1; { add to 1 to left }
WHILE (thearray[left] > midpoint) DO { is thearray[right] > midpoint}
left := left - 1; {set right minus 1 }
IF (right <= left) THEN { is left <>
BEGIN
swap (thearray[right], thearray[left]);
right := right + 1; {set left + 1 }
left := left - 1; {set right - 1}
END;
UNTIL right > left; { end repeat }
IF (first <>
qsort (thearray, first, left);
IF (right <>
qsort(thearray, right, last);
END;
{ procedure for the quick sort }
PROCEDURE quicksort(thearray : thearraytype ; elementsinuse : integer);
VAR
first : integer;
BEGIN
first := 1;
last := elementsinuse;
IF first <>
qsort(thearray, first, last) { the quick sort process, call the qsort procedure }
END;
BEGIN { main }
thearray[1] := 4;
thearray[2] := 15;
thearray[3] := 54;
thearray[4] := 64;
thearray[5] := 84;
thearray[6] := 5;
thearray[7] := 24;
thearray[8] := 1;
thearray[9] := 8;
thearray[10] := 9;
quicksort(thearray, elementsinuse)
END. {main }