1. The first element in the array is assumed to be sorted. Take the second element and store it separately in key.

    1. Comparekeywith the first element. If the first element is greater thankey, then key is placed in front of the first elemet.
  2. Now, the first two elements are sorted.

    1. Take the third element and compare it with the elements on the left of it. Placed it just behind the element smaller than it. If there is no element smaller than it, then place it at the begining of the array.
  3. In a similar way, place every unsorted element at its correct position.