#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#define MAX 5
void main()
{
int
maxstk,top=-1,n,a[MAX],i;
char ch;
clrscr();
//PUSH OPERATION
do
{
if(top>=MAX-1)
{
cout<<"Stack
is overflow"<<endl;
break;
}
else
{
top++;
cout<<"Enter
element to be pushed: ";
cin>>n;
a[top]=n;
}
cout<<"Do
you want to push more elements(y/n):- ";
cin>>ch;
}while(ch=='y');
cout<<"After
push operation elements of the stack are:-"<<endl;
for(i=0;i<=top;i++)
{
cout<<a[i]<<"\t";
}
cout<<endl<<"Inverse
of stack is:-"<<endl;
for(i=top;i>=0;i--)
{
cout<<
a[i] <<"";
}
getch();
}
No comments:
Post a Comment