Sorting en pascal
bueno ense;are aki un metodo d sorting en pascal, (metodo de ordenamiento) espero les sea d mucha ayuda.
SELECTING SORTING
PROGRAM pruebasorting; { nombre del programa}
{ made by MoYo }
USES CRT;
CONST { usaremos la constante numberofelementsinuse = el numero de elementos en el array
que son 10}
numberofelementsinuse = 10;
TYPE { declaramos el array con los 10 elementos }
thearraytype = array [1..10] of byte;
VAR {declaramos las variables q usaremos }
currentindex, leftmostindex, locationoflowestvalue : integer; {currentindex = numeroenuso , lefmosindex = numero menos, locationflowestvalue = localizacion de el numero menor}
lowestvalue : integer; {numero mas bajo}
thearray : thearraytype; {el array}
{iniciamos una procedure}
PROCEDURE sorting (VAR thearray : thearraytype;
numberofelementsinuse : integer);
VAR {declaramos las variables q seran usadas en la procedure}
currentindex, leftmostindex, locationoflowestvalue : integer;
lowestvalue : integer;
BEGIN
IF (numberofelementsinuse >= 2) THEN
BEGIN
leftmostindex := 1;
REPEAT
lowestvalue := thearray[leftmostindex];
locationoflowestvalue := leftmostindex;
FOR currentindex := leftmostindex + 1 TO numberofelementsinuse DO
IF (thearray[currentindex] < style="color: rgb(51, 51, 255);"> BEGIN
lowestvalue := thearray[currentindex];
locationoflowestvalue := currentindex;
END;
thearray[locationoflowestvalue] := thearray[leftmostindex];
thearray[leftmostindex] := lowestvalue;
INC (leftmostindex);
UNTIL (leftmostindex = numberofelementsinuse);
END;
END;
BEGIN
thearray[1] := 1;
thearray[2] := 7;
thearray[3] := 8;
thearray[4] := 6;
thearray[5] := 10;
thearray[6] := 15;
thearray[7] := 45;
thearray[8] := 23;
thearray[9] := 2;
thearray[10] := 14;
sorting(thearray, numberofelementsinuse) ;
END.