Meu prof. me passou o "melhor" codigo de ordenção do metodo BubbleSort, mas não estou conseguindo rodar ele, acho q tem algo errado nele !! se puderem me ajudar agradeço !!
Código:
public class BubbleSort3 { public static void main(String args [ ]) { int X[ ] = new int[5]; int n, i, aux, troca; Scanner entrada = new Scanner (System.in); // carregando os números no vetor for ( i = 0 ; i <= 4 ; i++) { System.out.println(“Digite os 5 números”); X [ i ] = entrada.nextInt( ); } // ordenando de forma crescente n = 1; troca = 0; for(i = 0; i <= 3; i++) { if ( X [ i ] < X [ i +1]) { troca = 1; aux = X [ i ]; X [ i ] = X [ i +1]; X [ i +1] = aux; } } n = n + 1; } // Mostrando o vetor ordenado for ( i = 0 ; i <= 4 ; i++) { System.out.println( X [ i ] + " "); } } }
Comment