No. of comparisons: 0 No. of swaps: 0
gap = length(list)
sorted = false
shrink = 1.3
while(sorted ==
false)
gap = floor(gap/shrink)
if(gap <= 1)
gap = 1
sorted =
true
i = 0
while(i + gap <
length(list))
if(list[i]
> list[i + gap])
swap(list[i] > list[i+gap])
sorted =
false
i += 1
---------------------
| SHORT EXPLANATION |
---------------------
1. Set gap to the length of the list, the shrink factor to
1.3 and sorted to false
2. Calculate the new gap (-> gap = floor(gap/shrink))
3. Iterate over the list and compare list[i] and
list[i+gap]
- If list[i] is bigger than list[i+gap] swap the
elements
4. Repeat 2 - 4 until the list is sorted