Last active
August 10, 2017 22:10
-
-
Save thauansrx/75c49e19e38d6d652d0dcc02d2a6238b to your computer and use it in GitHub Desktop.
***Algoritmo de Ordenação Bubble Sort
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
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