0

Hello Members,

Can anyone please help me out with the concept of INSERTION AND DELETION OF ELEMENTS IN ARRAY..

I have understood the logic behind this, but i am facing problem with the coding thing.. i am not able to get it properly..

can anyone here pls help me out....

3
Contributors
3
Replies
7
Views
5 Years
Discussion Span
Last Post by mridul.ahuja
0

I have understood the logic behind this, but i am facing problem with the coding thing.. i am not able to get it properly..

If the problem is in the code then post the code so we may help

0

If the problem is in the code then post the code so we may help

its the algorithm here..

INSERT(ARR,N,K,ITEM) //N-NO OF ELEMENTS,K-POSITION,ITEM-TO BE INSERTED
SET J:= N
REPEAT STEPS 3 AND 4 WHILE J>=K
SET ARR[J+1]:=ARR[J]
SET J:=J-1
SET ARR[K]:=ITEM
SET N:=N+1
EXIT

-1

Dude..you can use these functions for insertion and deletion..

num : number to insert/delete
pos : position where it will be inserted/deleted

Example taking array of size 5...

Insertion Function:-

void insert(int num, int pos)
  {
   for(int i=4; i>=pos;i--)
     arr[i]=arr[i-1];
   arr[i]=num;
  }

Deletion Function :-

void a_delete(int pos)
  {
   for(int i=pos; i<=4;i++)
   arr[i-1]=arr[i];
   arr[i-1]=0;
  }

Edited by Narue: Added code tags

Votes + Comments
Please don't give away answers to people who clearly haven't put in any effort.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.