#include
#include
class node
{
public:
int info;
node *next;
};
class stack
{
private:
node *top;
public:
stack()
{
top=NULL;
}
int empty()
{
if(top==NULL)
return(1);
else
return(0);
}
void push(int passed_value)
{
node *temp;
if(top==NULL)
{
top=new node;
top->info=passed_value;
top->next=NULL;
}
else
{
temp=new node();
temp->info=passed_value;
temp->next=top;
top=temp;
}
cout<<"\n"<
int x=tmp->info;
delete(tmp);
return(x);
}
void display()
{
if(top==NULL)// if stack is empty
cout<<"\nStack Empty\n"; else { node *currentnode; cout<<"The Contents of the Stack are:\n"; for(currentnode=top;currentnode!=NULL;currentnode=currentnode->next)
cout<
switch(choice)
{
case 1:
cout<<"Enter an element: "; cin>>choice;
mystack.push(choice);
getch();clrscr();
break;
case 2:
if(mystack.empty())
{
cout<<"\nStack Empty\n";
break;
}
x=mystack.pop();
cout<<"\nThe Popped element is : "<
break;
case 3:
mystack.display();
getch();clrscr();
break;
case 4:
exit(0);
break;
default:
cout<<"\nEnter Correct Choice:";
}
}
}
No comments:
Post a Comment