Quick Sort
c:
/*
-Victor de la Rocha
-vyk2rr@gmail.com
-www.algoritmia.info
-Jueves 24/FEB/05
-Quick Sort recursivo (Ordenamiento rapido iterativo)
-Program that orders an adjustment with the arrangement quick sort arrangement
-Programa que ordena un arreglo con el algoritmo de ordenamiento rapido recursivo o iterativo
*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h> //libreria con el prototipo de la funcion rand()
int quicksort_iterativo(int A[],int ini,int fin){
int _ini_,_fin_,pos,aux,band;
_ini_=ini;
_fin_=fin;
pos=ini;
band=1;
while (band==1){
band=0;
while((A[pos]<=A[_fin_])038;038;(pos!=_fin_)){
_fin_--;
}
if (pos!=_fin_){
aux=A[pos];A[pos]=A[_fin_];
A[_fin_]=aux;
pos=_fin_;
while ((A[pos]>=A[_ini_])038;038;(pos!=_ini_)){
_ini_++;
}
if(pos!=_ini_){
band=1;
aux=A[pos];
A[pos]=A[_ini_];
A[_ini_]=aux;
pos=_ini_;
}
}
}
if ((pos-1)>ini){
quicksort_iterativo(A,ini,pos-1);
}
if (fin>(pos+1)){
quicksort_iterativo(A,pos+1,fin);
}
return 0;
}
void main(){
int A[10],c;
clrscr();
randomize();
for(c=1;c<=10;c++){
A[c]=rand()%10;
printf("%d, ",A[c]);
}
printf("\nValores ordenados: \n");
quicksort_iterativo(A,1,10);
for(c=1;c<=10;c++){
printf("%d, ",A[c]);
}
getch();
}
-Victor de la Rocha
-vyk2rr@gmail.com
-www.algoritmia.info
-Jueves 24/FEB/05
-Quick Sort recursivo (Ordenamiento rapido iterativo)
-Program that orders an adjustment with the arrangement quick sort arrangement
-Programa que ordena un arreglo con el algoritmo de ordenamiento rapido recursivo o iterativo
*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h> //libreria con el prototipo de la funcion rand()
int quicksort_iterativo(int A[],int ini,int fin){
int _ini_,_fin_,pos,aux,band;
_ini_=ini;
_fin_=fin;
pos=ini;
band=1;
while (band==1){
band=0;
while((A[pos]<=A[_fin_])038;038;(pos!=_fin_)){
_fin_--;
}
if (pos!=_fin_){
aux=A[pos];A[pos]=A[_fin_];
A[_fin_]=aux;
pos=_fin_;
while ((A[pos]>=A[_ini_])038;038;(pos!=_ini_)){
_ini_++;
}
if(pos!=_ini_){
band=1;
aux=A[pos];
A[pos]=A[_ini_];
A[_ini_]=aux;
pos=_ini_;
}
}
}
if ((pos-1)>ini){
quicksort_iterativo(A,ini,pos-1);
}
if (fin>(pos+1)){
quicksort_iterativo(A,pos+1,fin);
}
return 0;
}
void main(){
int A[10],c;
clrscr();
randomize();
for(c=1;c<=10;c++){
A[c]=rand()%10;
printf("%d, ",A[c]);
}
printf("\nValores ordenados: \n");
quicksort_iterativo(A,1,10);
for(c=1;c<=10;c++){
printf("%d, ",A[c]);
}
getch();
}
Arreglo original 140, 10, 5, 9, 16, 8, 0, 1, 52 Arreglo ordenado 0, 1, 5, 8, 9, 10, 16, 52, 140