Last active
November 14, 2015 04:37
-
-
Save tiagox/d54f3ccdd0bac9bde928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrdenadorPorSeleccion { | |
public void ordenar(int[] vector) { | |
int posicionMax; | |
for (int i = 0; i < vector.length; i++) { | |
posicionMax = obtenerPosicionDelValorMaximo(vector, 0, | |
vector.length - i); | |
intercambiar(vector, posicionMax, vector.length - 1 - i); | |
} | |
} | |
private int obtenerPosicionDelValorMaximo(int[] vector, int inicio, int fin) { | |
int posicionMax = inicio; | |
int valorMax = vector[inicio]; | |
for (int i = inicio; i < fin; i++) { | |
if (vector[i] > valorMax) { | |
posicionMax = i; | |
valorMax = vector[i]; | |
} | |
} | |
return posicionMax; | |
} | |
private void intercambiar(int[] vector, int a, int b) { | |
int aux = vector[b]; | |
vector[b] = vector[a]; | |
vector[a] = aux; | |
} | |
/** | |
* Este método sirve sólo por propositos de realizar pruebas en Dr. Java. | |
*/ | |
public void mostrar(int[] vector) { | |
for (int i = 0; i < vector.length; i++) { | |
System.out.println(vector[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment