Ordenação Pelo Método Bolha
Publicado por Antonio Delvair Zaneti / CornelioDigital.com (última atualização em 28/07/2017)
[ Hits: 3.405 ]
Homepage: www.nossoclick.com
Neste arquivo realizaremos a ordenação pelo método bolha, inserindo aleatoriamente 1000 elementos e calculando o tempo utilizado na ordenação.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package programacaojava;
import java.io.*;
/**
*
* @author azaneti
*/
public class ProgramacaoJava {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
int quantidade = 10000;
int[] vetor = new int[quantidade];
for (int i=0; i<vetor.length; i++)
{
vetor [i]=(int)(Math.random()*quantidade);
}
long tempoInicial = System.currentTimeMillis();
bubbleSort (vetor);
long tempoFinal = System.currentTimeMillis();
System.out.println("Executado em " + (tempoFinal - tempoInicial)+ "ms");
}
private static void bubbleSort(int vetor[])
{
boolean troca = true;
int aux;
while(troca){
troca=false;
for (int i=0; i<vetor.length -1; i++)
{
if (vetor[i]>vetor[i+1]){
aux = vetor[i] ;
vetor[i]=vetor[i+1];
vetor[i+1]=aux;
troca = true;
}
}
}
}
}
Funções matemáticas no plano cartesiano
Mensagem usando opção gráfica JOptionPane
Nenhum comentário foi encontrado.
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
[Resolvido] VirtualBox can't enable the AMD-V extension
Como verificar a saúde dos discos no Linux
Como instalar , particionar, formatar e montar um HD adicional no Linux?
Como automatizar sua instalação do Ubuntu para desenvolvimento de software.
Quais os códigos mais dificeis que vcs sabem fazer? (4)
Não consigo instalar distro antiga no virtualbox nem direto no hd (8)
Fiz uma pergunta no fórum mas não consigo localizar (14)
Upscaling com imagem cortada no monitor secundário ao usar iGPU Multi ... (1)
Servidor Ubuntu 24.04 HD 500 não tenho espaço na \home\adminis... [RES... (8)









