NOTE n is the size of the array

INSERTION

Array = {11, 12, 13, 14}; n = 4; insert 15 at position 2; posi = 2;

  • FORWARD SHIFTING
for(int i = n - 1; i >= posi - 1; i--)
{
	array[i+1] = array[i];
}

  • assign value to be inserted at the target index

  • n++

DELETION

Array = {11, 12, 13, 14}; n = 4;

DELETE position 2 Posi = 2;

  • BACKWARD SHIFTING
for(int i = posi - 1; i< n; i++)
{
	array[i] = array[i+1];
}