Created
May 17, 2016 01:00
-
-
Save rodrigozan/31706ff8117b4bb854329c2e86146310 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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