Insertion sort (pseudo-code lightly adapted from Cormen) of an array A with N elements Insertionsort (A) (1) for j = 1 to N-1 (2) do key = A[j] // insert key into sorted sequence A[0] ... A[j-1] // first shove all larger value rightwards to make space (3) i = j-1 (4) while i >= 0 and A[i] > key (5) do A[i+1] = A[i] (6) i = i-1 // then insert the key value into the space (7) A[i+1] = key