Link List Program Data Structure :: Array

Link List Program Data Structure :: Array :: INSERT

#include<iostream.h>
#include<stdlib.h>
#define L 0
#define U 10
void main()
{
int a[U],i,loc,ins,size;
cout<<“Enter the size of an array:”;
cin>>size;
if(size>10)
{
cout<<“Invalid Size”;
exit(1);
}
else
{
for(i=L;i<size;i++)
{
cout<<“Enter a[“<<i<<“]”;
cin>>a[i];
}
}
if(size==10)
cout<<“Insertion won’t be possible”;
else
{
cout<<“Enter the location:”;
cin>>loc;
loc=loc-1;
if(loc>size||loc<L||U<size)
cout<<“invalid location”;

else
{
cout<<“enter the value of element : “;
cin>>ins;
size+=1;
for(i=size;i>loc;i–)
{
//if(loc==size)
// break;
//else
a[i]=a[i-1];
}
a[loc]=ins;
for(i=L;i<size;i++)
cout<<a[i]<<endl;
}
}
}

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.