#include<iostream.h>
#include<conio.h>
struct node { int roll;
char name[20];
float total;
node *next; };
class stack
{
node *top;
public :
stack()
{ top=NULL;}
void push();
void pop();
void display();
};
void stack::push()
{ node *temp;
temp=new node;
cout<<“Enter roll :”;
cin>>temp->roll;
cout<<“Enter name :”;
cin>>temp->name;
cout<<“Enter total :”;
cin>>temp->total;
temp->next=top;
top=temp; }
void stack::pop()
{ if(top!=NULL)
{
node *temp=top;
top=top->next;
cout<<temp->roll<<temp->name<<temp->total<<“deleted”;
delete temp;
}
else
cout<<“Stack empty”; }
void stack::display()
{
node *temp=top;
while(temp!=NULL)
{
cout<<temp->roll<<temp->name<<temp->total<<” “;
temp=temp->next;
} }
void main()
{
stack st;
char ch;
do
{
cout<<“stack options\nP push \nO Pop \nD Display \nQ quit”;
cin>>ch;
switch(ch)
{ case ‘P’: st.push();break;
case ‘O’: st.pop();break;
case ‘D’: st.display();break;
}
}while(ch!=’Q’);
}
No comments:
Post a Comment