C++ Program – Insert Delete from 1-D array

by Nideesh C on May 2, 2011 · 0 comments

in C++




//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 Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C++ Program – Insert & Delete an element from array
  2. C++ program – Perform Insert, Delete, Search an element into a binary search tree
  3. C++ Program – Array Based Representation of Linear List using templates
  4. C program to accept an array of integers and delete the specified integer from the list
  5. C++ Program – Calculator

Leave a Comment

Previous post:

Next post: