PROFESORA: LIC.
TAYDE NANCY CHORA PORTILLA
ASIGNATURA: PROGRAMACION II
CARRERA: ICO GRUPO: G-22 [Link]
ALUMNA: GUADALUPE MONSERRAT RAMIREZ SANCHEZ
CODIGO FUENTE DEL PROGRAMA “ReducerRecursivo”
//Guadalupe Monserrat Ramirez Sanchez
import [Link];
public class QuickSortRecursivo {
static Scanner entrada = new Scanner([Link]);
static int arreglo[];
public static void main(String[] args) {
int n;
[Link]("¿Cuantos elementos desea insertar?: ");
n = [Link]();
arreglo = new int[n];
for (int i = 0; i < [Link]; i++) {
[Link]("Valor " + i + ": ");
arreglo[i] = [Link]();
}
[Link]("\nArreglo original:");
for (int i = 0; i < [Link]; i++) {
[Link](arreglo[i] + " ");
}
reducerrecursivo(0, [Link] - 1);
[Link]("\n\nArreglo ordenado:");
for (int i = 0; i < [Link]; i++) {
[Link](arreglo[i] + " ");
}
}
// METODO RECURSIVO QUICKSORT
public static void reducerrecursivo(int ini, int fin) {
int izq;
int der;
int pos;
int aux;
int flag;
izq = ini;
der = fin;
pos = ini;
flag = 1;
while (flag == 1) {
flag = 0;
while ((arreglo[pos] <= arreglo[der]) && (pos != der)) {
der = der - 1;
}
if (pos != der) {
aux = arreglo[pos];
arreglo[pos] = arreglo[der];
arreglo[der] = aux;
pos = der;
while ((arreglo[pos] >= arreglo[izq]) && (pos != izq)) {
izq = izq + 1;
}
if (pos != izq) {
flag = 1;
aux = arreglo[pos];
arreglo[pos] = arreglo[izq];
arreglo[izq] = aux;
pos = izq;
}
}
}
if ((pos - 1) > ini) {
reducerrecursivo(ini, pos - 1);
}
if (fin > (pos + 1)) {
reducerrecursivo(pos + 1, fin);
}
}
}