Ordenação Pelo Método Bolha
Publicado por Antonio Delvair Zaneti / CornelioDigital.com (última atualização em 28/07/2017)
[ Hits: 3.229 ]
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; } } } } }
Existência de triângulo, em Java
Nenhum coment�rio foi encontrado.
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Visualizar arquivos em formato markdown (ex.: README.md) pelo terminal
Dando - teoricamente - um gás no Gnome-Shell do Arch Linux
Como instalar o Google Cloud CLI no Ubuntu/Debian
Mantenha seu Sistema Leve e Rápido com a Limpeza do APT!
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)
Alguém já usou o framework Avalonia para desenvolver interfaces de usu... (2)
Gestão de Ambiente em uma rede Linux (3)