Skip to content

Instantly share code, notes, and snippets.

@rodrigozan
Created May 17, 2016 01:00
Show Gist options
  • Save rodrigozan/31706ff8117b4bb854329c2e86146310 to your computer and use it in GitHub Desktop.
Save rodrigozan/31706ff8117b4bb854329c2e86146310 to your computer and use it in GitHub Desktop.
public class InsertionSort2 {
public static void main(String[] args) {
//Estrutura básica
//Valores a serem ordenados
int vetor[] = {22, 9, 7, 6, 1, 49, 35, 3, 0};
//Armazenam o menor valor e o índice de menor valor
int valor, i;
//Compara com os outros valores
for (i = 0; i < vetor.length -1; i++) {
valor = vetor[i];
for (int j = i; j > 0; j--) {
if(vetor[j] < vetor[j-1]){
valor = vetor[j];
vetor[j] = vetor[j-1];
vetor[j-1] = valor;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment