**Example Code:**

procedure Insertion( var a : anarray; N : integer); var i, j, v : integer; begin for i := 2 to N do begin v := a[i] j := i; {Short circuit evaluation is assumed for the AND in the while loop.} while (j > 1) AND (a[j-1] > v) do begin a[j] := a[j-1] j := j-1 end; a[j] := v; end; end;Back to Sorting Algorithms