Shell sort can be considered as an improvement of insertion sort based on two reasons: 1) Insertion sort is efficient if the input is "almost sorted". 2) Insertion sort is typically inefficient because it moves values just one position at a time.
class ShellSortAlgorithm { public void ShellSort(int[] array) { int gap = array.Length / 2; for (int i = gap; i > 0; i /= 2) { // insertion sort for (int j = i; j + i <= array.Length; j += i) //start from i { int key = array[j]; int f = j; while (f - i >= 0 && array[f - i] > key) { array[f] = array[f - i]; f -= i; } array[f] = key; } } } }