3.Stack using linked list
3.Stack using linked list
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct node
int data;
struct node*link;
};
class Stack
node*top;
public:
Stack()
top=NULL;
void push()
node*temp=new node;
cin>>temp->data;
temp->link=top;
top=temp;
void pop()
{
if (top==NULL)
return;
top=top->link;
void show()
node*temp=top;
while(temp!=NULL)
cout<<temp->data<<"\t";
temp=temp->link;
};
void main()
clrscr();
Stack s;
int ch;
while(1)
{
cout<<"\n stack operation usng linked list:";
cout<<"\n\t menu\n\t1.push\n\t2.pop\n\t3.show\n\t4.exit\n:";
cin>>ch;
switch(ch)
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.show();
break;
case 4:
exit(0);
};