Shadow Administrador
Cantidad de envíos : 408 Edad : 39 Ubicación : Gualeguaychu Fecha de inscripción : 10/04/2008
| Tema: quick sort para pascal Miér Mayo 07, 2008 1:25 pm | |
| Aqui les dejo el codigo de el quick sort para pascal, este codigo yo lo hice PROGRAM quicksortin;{ MoYo }USES CRT;CONSTelementsinuse = 10; { number of elements in the array }TYPEthearraytype = array [1..elementsinuse] OF INTEGER; { the array type }VARthearray : 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);VARright, 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 > midpoint) DO { is thearray[right] > midpoint} left := left - 1; {set right minus 1 } IF (right <= left) THEN { is left <> BEGIN swap (thearray[right], thearray); 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);VARfirst : integer;BEGINfirst := 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 } Bubble sort en pascalBUBBLE SORT CODE PROGRAM bubblesorting;{ MoYo } USES CRT; CONST elementsinuse = 10; TYPE thearraytype = array [1..10] OF INTEGER; VAR currentindex, currentpass : integer; tempvalue : integer; thearray : thearraytype; PROCEDURE bubble (thearray : thearraytype; elementsinuse : integer); BEGIN IF elementsinuse > 1 THEN FOR currentpass := 1 to elementsinuse - 1 DO FOR currentindex := 1 to elementsinuse - 1 DO IF (thearray[currentindex + 1 ] <>
Última edición por Shadow el Miér Mayo 07, 2008 2:17 pm, editado 2 veces | |
|
ENANOMAHN MOD's
Cantidad de envíos : 50 Edad : 35 Ubicación : Gualeguaychu Fecha de inscripción : 14/04/2008
| Tema: Re: quick sort para pascal Miér Mayo 07, 2008 2:24 pm | |
| mm para qe es ese codigooo shadows? | |
|