i am write a code to print element in stack in reverse order
i need two stack to push from first and pop to other
but i have something error ..
#include<iostream.h>
#include<process.h>
struct stack{
stack s1,s2;
int info;
};
class stacks {
private:
stack top;
int x;
public:
s1.stack(){top=-1;}
s2.stack(){top=-1;}
void menu(){
int choice;
cout<<"\n1- push ,,,, 2- pop ,,,,, 3- traverse ,,, ,,5-exit\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter num";
cin>>x;
s1.push (x);}
break;
case 2:
if(isempty())
cout<<"empty";
else {
x=s1.pop();
cout<<"num delder="<<x;
s2.push(x);
cout<<"num enter="<<x;
}
break;
case 3:
if(isempty())
cout<<"empty";
else {
cout<<"the list is ";
s1.traverse();}
break;
case 4:
exit(0);
default:
cout<< " invalid choice ";
}
}
bool isempty( )
{
if (top==-1)
return true ;
else
return false ;
}
void traverse() {
stack *i;
do{
cout<<i->info;
i=i->next;
}
while(i!=NULL);
}
void push(int x){
stack *p=new stack;
p->info=x;
p-<next=NULL;
if(top==NULL)
top=p;
else
{
p->next=top;
top=p;
}
int pop()
{
stack*t;
x=top->info;
x=top;
top=top->next;
delste t;
return x;
}
};
void main()
{
stacks m;
while (1)
m.menu();
}