#include<iostream.h>
#include<conio.h>
void insert_top(int *,int &,int);
void insert_end(int *,int &,int);
void insert_k(int *,int &,int);
int *ptr,*s,item,i;
int n=0;
void main()
{
clrscr();
s=ptr;
cout<<endl<<"enter the no. of elements :";
cin>>n;
cout<<endl<<"enter the elements :";
for(i=1;i<=n;i++)
{
cout<<endl<<"enter a["<<i<<"] =";
cin>>*(ptr+i);
}
cout<<endl<<"u ve entered ";
for(i=1;i<=n;i++)
{
cout<<endl<<"a["<<i<<"] = "<<*(ptr+i);
}
cout<<endl<<"enter the item : ";
cin>>item;
insert_top(ptr,n,item);
insert_end(ptr,n,item);
insert_k(ptr,n,item);
getch();
}
void insert_top(int *ptr,int &n,int item)
{
cout<<endl<<"n="<<n;
n=n+1;
cout<<endl<<"n="<<n;
int r;
int *o;
for(i=n;i>=1;i--)
{ o=(ptr+i);
r=*(ptr+(i-1));
*o=r;
}
o=(ptr+i+1);
*o=item;
for(i=1;i<=n;i++)
{
cout<<endl<<"a["<<i<<"] = "<<*(ptr+i);
}
}
void insert_end(int *ptr,int &n,int item)
{
cout<<endl<<"n="<<n;
n=n+1;
cout<<endl<<"n="<<n;
int *o;
o=(ptr+n);
*o=item;
for(i=1;i<=n;i++)
{
cout<<endl<<"a["<<i<<"] = "<<*(ptr+i);
}
}
void insert_k(int *ptr,int &n,int item)
{
int k;
int *o,r;
n=n+1;
cout<<endl<<"enter the kth pos :";
cin>>k;
for(i=n;i>=k;i--)
{
o=(ptr+i);
r=*(ptr+i-1);
*o=r;
}
*(ptr+k)=item;
for(i=1;i<=n;i++)
{
cout<<endl<<*(ptr+i);
}
}
No comments:
Post a Comment