Dec 18, 2006 16:34
package testwiese;
/**
* Summary description for Program
*/
public class Arra
{
public static void gibFeld(int[] feld)
{
for (int e = 0; e < feld.length; e++)
{
int h=feld[e];
System.out.print(h+",");
}
}
public static void wasTueIch(int[] feld)
{
int o=0;
int b = 0;
int i, j;
int temp;
int n = feld.length;
int distanz = n / 2;
while (distanz > 0)
{
for (i = distanz; i < feld.length; i++)
{
j = i - distanz;
while (j >= 0)
{
if (feld[j] > feld[j + distanz])
{
temp = feld[j];
feld[j] = feld[j + distanz];
feld[j + distanz] = temp;
j = j - distanz;
}
else
{
j = -1;
}
//innen
b++;
System.out.println();
System.out.print("innen: " + b + " -> ");
gibFeld(feld);
}
}
distanz = distanz / 2;
//aussen
o++;
System.out.println();
System.out.println("############# --- aussen: "+o);
gibFeld(feld);
System.out.println();
}
}
}
public class Program
{
public static void main(String[] args)
{
int nums[] = {56,22,79,27,9,30,61,4,69,38,52,89,23,17,68};
Arra.wasTueIch(nums);
}
}