No. of comparisons: 0
No. of swaps: 0
for i = 0 to length(list)
j = i
value = list[i]
while j > 0 && list[j-1]
> value
list[j] = list[j-1]
j--
list[j] = value
| SHORT EXPLANATION |
---------------------
1. Get the element you want to move to its position
2. Find its position by comparing it to the values left of
it
3. Remove it from the list and let the other elements move
up
4. Insert the element at its position in the sorted sublist
5. Repeat 1 - 4 until the list is sorted