{5, 2, 4, 6,1,3}

INSERTION-S ORT .A/
1 for j = 2 to A.length
2 key = A[j]
3 // Insert A[j ] into the sorted sequence A[1. . j - 1]
4 i = j - 1
5 while i > 0 and A > key
6 A[i + 1] = A
7 i = i - 1
8 A[i + 1] = key

Cormen, Thomas H. (2009-09-15). Introduction to Algorithms (Page 18). MIT Press. Kindle Edition.

    • 12 years ago
    Complete solution A++
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      insertionsort.java
    • attachment
      insertionsort.zip