I am trying to modify my shell sort algorithm to use Hibbard's increments rather than n/2.
I know that Hibbard's increments are 2k - 1, but I can't figure out how to incorporate that into my algorithm.
Any suggestions to help me move forward with this? I feel like I just can't figure this one out.
Here's the working version of what I have now, which is NOT using Hibbard's increments:
public void shellSort(int[] array, int lowindex, int highindex,
boolean reversed) {
int n = highindex - lowindex;
int increment;
int offset;
for (increment = n / 2; increment > 0; increment = increment / 2) {
for (offset = 0; offset < increment; offset++) {
ShellInsertionSort(array, offset, increment, lowindex,
highindex, reversed);
}
}
for (int ii = 0; ii < array.length; ii++) {
System.out.print(array[ii] + ", ");
}
System.out.println();
}
private static void ShellInsertionSort(int[] array, int offset,
int increment, int lowindex, int highindex, boolean reversed) {
int i, j;
for (i = offset + increment; i <= highindex; i = i + increment) {
int curr = array[i];
for (j = i - increment; j >= 0 && compare(curr, array[j], reversed); j = j
- increment) {
array[j + increment] = array[j];
}
array[j + increment] = curr;
}
}