ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Analisis Algoritmos


Enviado por   •  9 de Febrero de 2013  •  1.145 Palabras (5 Páginas)  •  419 Visitas

Página 1 de 5

import java.io.*;

import java.util.Random;

public class Analisis {

public static void main(String args []) throws java.io.IOException {

int tam=1,i,j,ord=7;

long tiempoInicio,totalTiempo;

char repetir,q;

BufferedReader equipo10 = new BufferedReader ( new InputStreamReader(System.in));

try{ //Llenado del arreglo de forma aleatoria de 0 a 999999 //

System.out.println("Introduce longitud del arreglo y este se llenara automaticamente");

tam = Integer.parseInt(equipo10.readLine());

}

catch(NumberFormatException nFE) {

System.out.println("\nNo es un numero");

quack();

}

if (tam<1){

System.out.println("\nArreglo no Valido para 0 o negativos");

quack();

}

int arreglo[]= new int[tam];

for(i=0;i<tam;i++){

arreglo[i]=(int)(Math.random()*1000000);

}

System.out.println("\nImprimir tu arreglo? si es muy grande tomara tiempo Pulsa 's' para Si \n");

q=(equipo10.readLine( ).charAt(0));

if ((q=='s')||(q=='S')){

System.out.println("\n\n\n");

imprime(arreglo);

System.out.println("\n\n\n");

}

do{

System.out.println("\nSelecciona tu Metodo de Ordenamiento, para ordenarse de menor a mayor");

System.out.println("1.- Burbuja \n2.- Quicksort\n3.- ShellSort\n4.- HeapSort\n5.- MergeSort\n6.- RadixSort");

try{ // Seleccion del metodo de ordenamiento a usar //

ord=Integer.parseInt(equipo10.readLine());

System.out.print("\n");

}

catch(NumberFormatException nFE) {

System.out.println("\nTu opcion no es un numero");

quack();

}

if (ord==1){

tiempoInicio = System.currentTimeMillis();

burbuja(arreglo);

totalTiempo = System.currentTimeMillis() - tiempoInicio;

imprime(arreglo);

System.out.println("\n\n\nEl tiempo total de la ejecucion del ordenamiento es :" + totalTiempo + " miliseg");

}

else if (ord==2){

tiempoInicio = System.currentTimeMillis();

quicksort(arreglo,0,(tam-1));

totalTiempo = System.currentTimeMillis() - tiempoInicio;

imprime(arreglo);

System.out.println("\n\n\nEl tiempo total de la ejecucion del ordenamiento es :" + totalTiempo + " miliseg");

}

else if (ord==3){

tiempoInicio = System.currentTimeMillis();

shellsort(arreglo);

totalTiempo = System.currentTimeMillis() - tiempoInicio;

imprime(arreglo);

System.out.println("\n\n\nEl tiempo total de la ejecucion del ordenamiento es :" + totalTiempo + " miliseg");

}

else if (ord==4){

tiempoInicio = System.currentTimeMillis();

heapsort(arreglo);

totalTiempo = System.currentTimeMillis() - tiempoInicio;

imprime(arreglo);

System.out.println("\n\n\nEl tiempo total de la ejecucion del ordenamiento es :" + totalTiempo + " miliseg");

}

else if (ord==5){

tiempoInicio = System.currentTimeMillis();

mergesort(arreglo,0,(arreglo.length-1));

totalTiempo = System.currentTimeMillis() - tiempoInicio;

imprime(arreglo);

System.out.println("\n\n\nEl tiempo total de la ejecucion del ordenamiento es :" + totalTiempo + " miliseg");

}

else if (ord==6){

tiempoInicio = System.currentTimeMillis();

radixsort(arreglo);

totalTiempo = System.currentTimeMillis() - tiempoInicio;

imprime(arreglo);

System.out.println("\n\n\nEl tiempo total de la ejecucion del ordenamiento es :" + totalTiempo + " miliseg");

}

else {

quack();

}

...

Descargar como (para miembros actualizados)  txt (7.4 Kb)  
Leer 4 páginas más »
Disponible sólo en Clubensayos.com