Pessoal estudei o metodo heap sort e estou tentando implementalo fiz tudo certinho mas não tão certinho assim e está ordenando tudo errado vou postar o código para que alguem possa me ajudar.
att
[code]public static void main(String args[]) {
int vetor[] = criarVetor();
metodoBolha(vetor);
}
public static int[] criarVetor() {
int[] vetor = new int[10];
for (int i = 0; i < 10; i++) {
vetor[i] = (int) (Math.random() * 100);
}
return vetor;
}
public static void metodoBolha(int vet[]) {
boolean houveTroca;
int aux;
do
{
houveTroca = false;
for (int i = 0; i < vet.length - 1; i++)
{
if (vet[i] > vet[i + 1]) {
aux = vet[i];
vet[i] = vet[i + 1];
vet[i + 1] = aux;
houveTroca = true;
}
}
} while (houveTroca);
for (int i = 0; i < vet.length; i++) {
System.out.print(vet[i] + ", ");
}
}
public class ForumTeste {
public static void main (String []args){
int vet [] = new int[10]; //Vetor com 10 posções
for (int i = 0 ;i<vet.length;i++){
vet[i]= (int)(1 + Math.random()*10); // cada posição do vetor recebe um valor aleatório entre 1 e 10
}
Arrays.sort(vet); // ordena vetor;
for (int i = 0 ;i<vet.length;i++){ // imprime vetor
System.out.println(vet[i]);
}
}