the array is sorted except the first one. For example, I have a list{5, 4, 2, 3 ,1}, after sorting the list is {5,1,2,3,4}.
public static void segmentedInsertionSort(AnyType[] list, int n, int h)
{
int j;
System.out.println("hello Nguyen");
System.out.println("the value of n is " + n + " "+ h);
AnyType temp;
for(int i = h; i < n; i++)
{
System.out.println("hello Ashley");
j = i - h;
while(j >0)
{
if (list[j].isBetterThan(list[j + h]))
{
temp = list[j];
list[j] = list[j + h];
list[j + h] = temp;
j = j - h;
System.out.println("hello Connie");
}
else
{
j = 0;
}
}
}
}
public static void shellSort(AnyType[] list, int n)
{
int h = 1;
while (h < n/3)
{
h = h*3 +1;
}
while(h > 0)
{
segmentedInsertionSort(list, n, h);
h = (h - 1)/3;
}
}