2
I implemented a logic of Selection Sort and would like to ask if it is correct. Because at the end of the process the result is expected, but went to make a real proof and found several algorithms but none similar to mine.
Follows the code.
int vetor[] = {9, 1, 3, 2, 5, 4, 7, 8, 6, 0};
int aux;
for(int i = 0; n = vetor.length; i < n; i++){
for(int j = 0; j < n - 1; j++){
if(vetor[j] > vetor[i]){
aux = vetor[i];
vetor[i] = vetor[j];
vetor[j] = aux;
}
}
}// fim do for
// aqui mando imprimir o vetor ordenado
for(int i = 0, n = vetor.length; i < n; i++){
System.out.println("" + vetor[i]);
}
You implemented Bubble Sort and not Selection Sort.
– mercador
a picture is worth a thousand words: algorithms in animations.
– Renan Gomes
Thank you guys! and Renan very good this visual example!
– Bruno de Moraes