Sunday, 31 August 2014

Filled Under: ,

C++ program to perform insertion and deletion operation in array

Share
C++ program to perform insertion and deletion operation in array:A simple C+ + program related to array which perform insertion and deletion operation.It is a menu driven program which ask the choice for insertion or deletion and according to user choice it perform operation.


C++ program to perform insertion and deletion operation in array

C++ program to perform insertion and deletion operation in array

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int n,x,c=0,e,ch,i,a[50],j;
cout<<"Enter Array lim"<<endl;
cin>>n;
cout<<"Enter array"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter Choice  1:Deletion  2Insertion"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter to be deleted"<<endl;
cin>>x;
for(i=0;i<n;i++)
{

if(a[i]==x)
{c++;
for(j=i;j<n;j++)
{
a[j]=a[j+1];
}
}
}
if(c==0)
cout<<"ENP"<<endl;
for(i=0;i<n-c;i++)
cout<<a[i]<<endl;
break;

case 2:
cout<<"Enter What & Where to be inserted"<<endl;
cin>>e>>x;
for(i=n;i>=x;i--)
a[i]=a[i-1];
a[x-1]=e;
for(i=0;i<=n;i++)
cout<<a[i]<<endl;
break;
}
getch();
}