Hey, I tweaked my code a bit to fix some obvious problems but I'm still having problems trying to implement a gap sort which is a bubble sort that instead of comparing neighboring elements to sort a list, it compares elements 'i' positions apart. Can anyone please help me?
Thanks for reading and here is my code:
public static <T extends Comparable<? super T>> void gapSort (T[] data, int i)
{
int position, scan;
T temp;
if(i > 0)
{
for (position = data.length - 1; position >= 0; position--)
{
for (scan = 0; scan <= position - 1; scan++)
{
if (i > scan)
{
if (data[scan].compareTo(data[scan+i]) > 0)
{
/** Swap the values */
temp = data[scan];
data[scan] = data[scan + i];
data[scan + i] = temp;
}
}
else
{
if (data[scan].compareTo(data[scan-i]) < 0)
{
temp = data[scan];
data[scan] = data[scan - i];
data[scan - i] = temp;
}
}
i--;
}
}
}
}