The Insertionsort Algorithm
p
...and
inserting it
in the place
that keeps
the sorted
side
arranged
from small
to large.
[0]
[1]
[2]
[3]
[4]
[5]
Sorted side
Unsorted side
...and insert this element at the correct spot of the sorted side.
In this example, the front element of the unsorted side is 20. So the 20 must be inserted before the number 45 which is already in the sorted side.