TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Estruturas de Dados

Por:   •  23/2/2017  •  Abstract  •  367 Palavras (2 Páginas)  •  146 Visualizações

Página 1 de 2

public static void main(String[] args) {

// TODO code application logic here

int tamanho;

tamanho =Integer.parseInt(JOptionPane.showInputDialog("Entre com a quantidade de elementos para o vetor"));

int vetor[]=new int[tamanho];

preencheVetor(vetor);

bubbleSort(vetor);

//selectionSort(vetor);

//insertSort(vetor);

mostraVetor(vetor);

}

public static void bubbleSort(int vetor []){

int aux; //variavel auxiliar utilizada durante a troca (inversão dos valores)

int tam = vetor.length; //

int cont =0;

for (int i=0; i < tam -1; i++){

cont+=1;

for(int j=i+1; j<tam; j++){

if (vetor[j] > vetor[i]){ //sinal grafico de > ou < nesse if ou while define se é cresc. ou descre.

aux = vetor[j];

vetor[j] = vetor [i];

vetor[i] = aux;

}

}

}

JOptionPane.showMessageDialog(null,"NUMERO DE COMPARAÇÕES: " + cont);

}

...

Baixar como (para membros premium)  txt (1.1 Kb)   pdf (38.7 Kb)   docx (10.6 Kb)  
Continuar por mais 1 página »
Disponível apenas no TrabalhosGratuitos.com