Ordenamiento Quick Sort
pascal:
Program OrdenRapido;
Uses Crt, Chuchox;
Const
Ret = 5;
Limite = 10;
Var
Lista : V2;
K,h : Integer;
Procedure Llenar(Var lista: V2);
Begin
For k:= 1 to limite do
Begin
Lista[k]:= Random(100);
Delay(50);
End;
Display(lista,h);
End;
Procedure Rapido (Var a: V2; n: Integer);
Procedure Partir (primero, ultimo: Integer);
Var
i,j : Integer;
central : Integer;
Procedure Intercambiar (Var m,n : Integer);
Var
aux : Integer;
Begin
aux := m;
m := n;
n := aux;
End;
Begin
i := primero;
j := ultimo;
central:= a[(primero + ultimo) Div 2 ];
Repeat
While a [i] < central Do i := I + 1;
While a [j] > central Do j := j - 1;
If i <= j Then
Begin
Intercambiar (a[i], a[j]);
i := i+1;
j := j-1;
End;
Until i> j;
If primero < j Then
Begin
partir (primero, j);
End;
If i < ultimo Then
Begin
partir (i,ultimo);
End;
h:= h + 4;
Display(lista,h);
End;
Begin
partir (1,n);
End;
{---------Principal----------}
Begin
ClrScr;
h:= 3;
Llenar(Lista);
h:= h + 4;
Rapido (Lista, Limite);
Repeat Until KeyPressed;
End.
Uses Crt, Chuchox;
Const
Ret = 5;
Limite = 10;
Var
Lista : V2;
K,h : Integer;
Procedure Llenar(Var lista: V2);
Begin
For k:= 1 to limite do
Begin
Lista[k]:= Random(100);
Delay(50);
End;
Display(lista,h);
End;
Procedure Rapido (Var a: V2; n: Integer);
Procedure Partir (primero, ultimo: Integer);
Var
i,j : Integer;
central : Integer;
Procedure Intercambiar (Var m,n : Integer);
Var
aux : Integer;
Begin
aux := m;
m := n;
n := aux;
End;
Begin
i := primero;
j := ultimo;
central:= a[(primero + ultimo) Div 2 ];
Repeat
While a [i] < central Do i := I + 1;
While a [j] > central Do j := j - 1;
If i <= j Then
Begin
Intercambiar (a[i], a[j]);
i := i+1;
j := j-1;
End;
Until i> j;
If primero < j Then
Begin
partir (primero, j);
End;
If i < ultimo Then
Begin
partir (i,ultimo);
End;
h:= h + 4;
Display(lista,h);
End;
Begin
partir (1,n);
End;
{---------Principal----------}
Begin
ClrScr;
h:= 3;
Llenar(Lista);
h:= h + 4;
Rapido (Lista, Limite);
Repeat Until KeyPressed;
End.
November 23rd, 2007 at 10:35 am
[...] Ordenamiento Quick Sort en Turbo Pascal [...]