import java.io.*;
class numeros
{
public static void main(String arg [] )throws Exception
{
DataInputStream Entrada = new DataInputStream (System.in);
int Z=0;
int F=0;
int j=1;
int k=0;
int aux;
System.out.println("cuantos numero ordenara");
System.out.println("");
Z=Integer.parseInt (Entrada.readLine());
System.out.println("");
int num[]=new int[Z];
for(int i=0;i<Z;i++)
{
System.out.println("ingrese numeros");
num[i]=Integer.parseInt (Entrada.readLine());
}
System.out.println("");
System.out.println("numeros sin ordenar");
System.out.println("");
for(int i=0;i<Z;i++)
{
System.out.print(num[i]+" ");
}
System.out.println("");
while (j<Z && F==0)
{
F=1;
k=0;
while (k<(Z-j))
{
if(num[k]>num[k+1])
{
aux=num[k];
num[k]=num[k+1];
num[k+1]=aux;
F=0;
}
k=k+1;
}
j=j+1;
}
System.out.println("");
System.out.println("");
System.out.println("numeros ya ordenados");
System.out.println("");
System.out.println("");
System.out.println("");
for(int i=0;i<Z;i++)
{
System.out.print(num[i]+" ");
}
System.out.println("");
}
}
SHELL
import java.io.*;
public class shell{
public static void main (String arg[] )throws Exception
{
DataInputStream entrada=new DataInputStream (System.in);
int Z;
System.out.println("CANTIDAD DE NUMEROS A ORDENAR");
Z=Integer.parseInt(entrada.readLine());
int A[]=new int [Z];
for(int i=0;i<Z;i++)
{
System.out.println("INGRESE NUMERO");
A[i
]=Integer.parseInt(entrada.readLine());
}
int k=A.length/2;
while (k>=1)
{
for (int subarray = 0; subarray < k; subarray++)
{
for (int i = k+subarray; i < A.length; i += k)
{
int v = A[i];
int j = i - k;
while (j >= 0 && A[j] > v)
{
A[j + k] = A[j];
j-=k;
}
A[j + k] = v;
}
}
k /= 2;
}
System.out.println(" ");
for(int i=0;i<Z;i++)
{
System.out.print(" "+A[i]);
}
}
}