Array Insertion

We can insert the elements wherever we want, which means we can insert either at starting position or at the middle or at last or anywhere in the array. After inserting the element in the array, the positions or index location is increased but it does not mean the size of the array is increasing.

Algorithm

  1. First get the element to be inserted, say x.
  2. Then get the position at which this element is to be inserted, say pos .
  3. Then shift the array elements from this position to one position forward,
    and do this for all the other elements next to pos.
  4. Insert the element x now at the position pos, as this is now empty.

Program using C