* Crear un programa en java que ordene datos mediante el metodo de la burbuja mejorada.
* Fuente: .....------ ErNeStO rOsAlEs CaRlOs ------.....
*********************************************
* InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS *
* InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ *
* EsTrUcTuRa De DaToS *
* ErNeStO rOsAlEs CaRlOs *
* ernestorosales@live.com *
*********************************************
*/
import java.io.*;
public class BurbujaOrdenaMejorada
{
public static void main (String args[])throws IOException
{
int d,t,k;
BufferedReader erc=new BufferedReader(new InputStreamReader(System.in));
System.out.println(" *****************************");
System.out.println(" * *");
System.out.println(" * MeToDo De BuRbUjA *");
System.out.println(" * *");
System.out.println(" *****************************");
System.out.println("\nIngresa el numero de datos a ingresar: ");
d=Integer.parseInt(erc.readLine());
int n[]=new int[d];
for(int i=0; i<d; i++)
{
System.out.println("Ingresa dato " +i+" :");
n[i]=Integer.parseInt(erc.readLine());
}
int tuopcion;
do
{
do
{
try
{
System.out.println("\n");
System.out.println(" **************************************");
System.out.println(" * Elige la opcion deseada: *");
System.out.println(" * *");
System.out.println(" * 1.- Sin orden(original) *");
System.out.println(" * 2.- Orden decendiente *");
System.out.println(" * 3.- Orden ascendente *");
System.out.println(" * *");
System.out.println(" * 4.- Salir *");
System.out.println(" * *");
System.out.println(" **************************************");
tuopcion=Integer.parseInt(erc.readLine());
if (tuopcion< 1 || tuopcion> 4)
System.out.println ("\nError **fuera del rango permitido**");
}
catch (NumberFormatException err)
{
tuopcion=0;
System.out.println("\n\n Error --no es numero--");
}
}while (tuopcion<1 || tuopcion>4);
switch(tuopcion)
{
case 1:
System.out.println("\nEl arreglo original es: ");
for(int i=0;i<n.length;i++)
{
System.out.print(" "+ n[i]);
}
break;
case 2:
boolean inter=true;
for(int j=0;j<n.length-1&&inter==true;j++)
{
inter=false;
for(int i=1;i<n.length-j;i++)
if(n[i-1]<n[i])
{
inter=true;
t=n[i-1];
n[i-1]=n[i];
n[i]=t;
}
}
System.out.println("\n\nLos datos en orden decreciente son: ");
for(int r=0;r<n.length;r++)
System.out.print(" "+n[r]);
break;
case 3:
boolean inte=true;
for(int l=0;l<n.length-1&&inte==true;l++)
{
inte=false;
for(int i=1;i<n.length-l;i++)
if(n[i-1]>n[i])
{
inte=true;
t=n[i-1];
n[i-1]=n[i];
n[i]=t;
}
}
System.out.println("\n\nLos datos en orden decreciente son: ");
for(int r=0;r<n.length;r++)
System.out.print(" "+n[r]);
break;
}
} while(tuopcion!=4);
}
}