//Downloaded From theonlinetutorials.com
//(C)2011.All rights reserved.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,x,i,a[50],ch,j,c=0,e;
cout<<"Enter array Limit"<<endl;
cin>>n;
for (i=0;i<n;i++)
cin>>a[i];
cout<<"Enter choice 1:Insertion 2:Deletion"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter Element to be deleted"<<endl;
cin>>x;
for(i=0;i<n;i++)
{
if (a[i]==x)
{
for(j=i;j<n;j++)
a[j]=a[j+1];
c++;
}
}
for(i=0;i<n-c;i++)
cout<<a[i]<<endl;
break;
case 2 :
cout<<"Enter Element and where to be inserted at";
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();
}
Not Satisfied ? Just search & get the result
Related posts:
- C++ Program – Insert & Delete an element from array
- C++ program – Perform Insert, Delete, Search an element into a binary search tree
- C++ Program – Array Based Representation of Linear List using templates
- C program to accept an array of integers and delete the specified integer from the list
- C++ Program – Calculator
