Insertion in Array - Data Structures

5

In the last post we have already discussed traversing an array. Now in this post we are going to discuss insertion in an array.

 Insertion in array

An element can be inserted in an array at a specified position.

In order to perform insertion operations,  the array should have enough capacity.

Note- When no position is specified it’s better to insert an element at the end.

Visual Representation

Let’s consider an array of 6 integers.

  10

20

30

50

  60

100

If we want to insert 40 item at position 3 then the procedure will be as follows -

Procedure


Algorithm


Code Snippet 1 - insertion operation



Code Snippet 2 - whole source code



Output


This was all for now, in the next post we will talk about deletion, searching, and sorting in an array.


Post a Comment

5Comments
  1. When you will post deletion?
    eagerly wating for deletion.

    ReplyDelete
  2. Nice! But why there is no copy button in source code?

    ReplyDelete
  3. hello! when are you coming back?

    ReplyDelete
Post a Comment