menu driven program to perform the following stack operations using a linked list: push pop and display elements.
#include<iostream.h>//header file i/o stream flow
#include<conio.h>
class Stack
{
int A[10];
int top;
public:
Stack()
{
top=-1;
}
void push();
void pop();
void show();
};
void Stack::push()
{
int x;
cout<<"Enter the value to push";
cin>>x;
if(top==-1)
top=0;
A[top++]=x;
}
void Stack::pop()
{
cout<<top;
cout<<" \n Element Poped is:"<<A[--top];
}
void Stack::show()
{
cout<<"\n top:";
for(int i=top-1;i>=0;i--)
cout<<A[i]<<"\t";
}
void main()
{
int choice;
Stack s;
do
{
cout<<"\n 1 push ";
cout<<"\n 2 pop ";
cout<<"\n 3 show";
cout<<"\n 4 exit";
cout<<"\n input your choice:";
cin>>choice;
switch(choice)
{
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.show();
break;
default:
cout<<"\n invalid input ";
}
}while(choice !=4);
getch();
}
is this program correct according to the question?