You are on page 1of 3

METODOS DE ORDENACION

IMPLEMENTAR LOS SIGUIENTES METODOS DE ORDENACION

1.- Burbuja

Burbuja(int[] numeros)
{
int temp;
for (int i = 0; i < numeros.Length; i++)
{
for (int k = i + 1; k < numeros.Length; k++)
{
if (numeros[i] > numeros[k])
{
temp = numeros[i];
numeros[i] = numeros[k];
numeros[k] = temp;
}
}
}
}

2.- Inserción

void Insercion(int[] numeros) {


int auxili;
int j;
for (int i = 0; i < numeros.Length ; i++)
{
auxili = numeros[i];
j = i - 1;
while (j >= 0 && numeros[j] > auxili)
{
numeros[j + 1] = numeros[j];
j--;
}
numeros[j + 1] = auxili;
}
}
3.- Shell

Shell(int[] numeros)
{
int salto = 0;
int sw=0;
int auxi = 0;
int e=0;
salto = numeros.Length / 2;
while (salto >0)
{
sw=1;
while (sw!=0)
{
sw=0;
e=1;
while (e <= (numeros.Length - salto))
{
if (numeros [e-1]>numeros [(e-1)+salto ])
{
auxi =numeros [(e-1)+salto ];
numeros [(e-1)+salto ]=numeros [e-1];
numeros [(e-1)]=auxi;
sw=1;
}
e++;
}
}
salto =salto /2;
}
}
4.- QuickSort
quicksort(numeros, 0, numeros.Length - 1);
public static void quicksort(int[] vector, int primero, int ultimo)
{
int i, j, central;
double pivote;

central = (primero + ultimo) / 2;


pivote = vector[central];
i = primero;
j = ultimo;

do
{
while (vector[i] < pivote) i++;
while (vector[j] > pivote) j--;

if (i <= j)
{
int temp;
temp = vector[i];
vector[i] = vector[j];
vector[j] = temp;
i++;
j--;

}
} while (i <= j);

if (primero < j)
{
quicksort(vector, primero, j);
}
if (i < ultimo)
{
quicksort(vector, i, ultimo);
}
}

You might also like