Skip to content

Instantly share code, notes, and snippets.

@thauansrx
Last active August 10, 2017 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thauansrx/75c49e19e38d6d652d0dcc02d2a6238b to your computer and use it in GitHub Desktop.
Save thauansrx/75c49e19e38d6d652d0dcc02d2a6238b to your computer and use it in GitHub Desktop.
***Algoritmo de Ordenação Bubble Sort
public class ordenacaoBubble {
public static void main(String[] args) {
/*
*Algoritmo de Ordenacao Bubble Sort
*/
int vetor[] = {3, 9, 5, 2, 10, 1, 4, 7, 6, 8};
int aux;
boolean controle;
for (int i = 0; i < vetor.length; i++) {
controle = true;
for (int j = 0; j < (vetor.length - 1); j++) {
if (vetor[j] > vetor[j + 1]) {
aux = vetor[j];
vetor[j] = vetor[j + 1];
vetor[j + 1] = aux;
controle = false;
}
}
if(controle){
break;
}
}
for (int i = 0; i < vetor.length; i++) {
System.out.print(vetor[i] + " ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment