Objective
Create a Python program that sorts a list with the insertion sort algorithm and counts the shifts it performs.
Instructions
- Read a line with integers separated by spaces.
- For each position
ifrom 1 tolen(list) - 1: storekey = list[i]and shift to the right the previous elements that are greater than the key (each shift adds 1 to the counter); then place the key in its gap. - Show
Result: n1 n2 ...and, on another line,Shifts: N.
12 11 13 5 6
Result: 5 6 11 12 13
Shifts: 7
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise