See Insertion sort run
Sort an array one item at a time. Take the next item and move it left until the item before it is not larger. Use the buttons or the keys: Space plays and pauses, the arrow keys step, Home and End jump.
INSERTION-SORT(A)- 1
for i ← 1 to n − 1 do - 2
key ← A[i] - 3
j ← i − 1 - 4
while j ≥ 0 and A[j] > key do ▷ > and not ≥ keeps the sort stable - 5
A[j + 1] ← A[j] - 6
j ← j − 1 - 7
A[j + 1] ← key
Read the full page about Insertion sort. To put this player on your site, use <iframe src="https://algorithm.tamnd.com/embed/insertion-sort/" width="100%" height="520"></iframe>.