Algoritmos 4
- 1. UNIVERSIDAD CENTRAL DEL ECUADOR
NOMBRE: Sánchez Eddy ESCUELA: Ciencias
MATERIA: Algoritmos FACULTAD: Ingeniería
FECHA: 12-04-2012
Clase Main
package metodo_shell;
import java.io.*;
/**
* @author Sanchez Eddy
*/
public class Metodo_Shell {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int limite;
System.out.println("Ingrese cuantos numeros desea generar: ");
limite=Integer.parseInt(in.readLine());
int[]x= new int[limite];
int dato;
for(int i=0;i<=limite-1;i++)
{
x[i]=(int) ((Math.random()*20)+1);
}
System.out.println("Elementos del Arreglo Desordenado");
for(int i=0; i<x.length;i++)
{
System.out.print(x[i]+" ");
}
System.out.println("n");
Shell obj =new Shell();
obj.Oshell(x, limite);
}
}
Clase Ordenamiento
package metodo_shell;
/**
* @author Sanchez Eddy
*/
public class Shell {
public static void Oshell(int x[],int n){
int b=0, t=0;
do{
n=n/2;
for(int i=0;i<x.length;i++){
for(int j=0; j<(x.length-1)-(n); j++)
- 2. {
if(x[j]>x[j+1])
{
t = x[j];
x[j] = x[j+1];
x[j+1] = t;
for(int k=0; k<x.length;k++)
{
System.out.print(x[k]+" ");
}
System.out.println();
}
}
}
}while(n>=1);
System.out.println("nArreglo Ordenado");
for(int i=0; i<x.length;i++)
{
System.out.print(x[i]+" ");
}
System.out.println("");
}
}
Impresión