/*stack using linked list */ y=pop();
#include <stdio.h> printf("Pushed item is : %d" ,y);
#include <conio.h> break;
#include <malloc.h> case 3:
#include <stdlib.h>
printf("\nThe Given List is\n");
struct stack print();
{ }
int item; printf("\n Continue 1/0");
struct stack *next; scanf("%d",&ch);
}; }while(ch==1);
struct stack *top }
struct stack *st=NULL; void print(void)
{ struct stack *t;
void push(int); t=st;
void print(void); while(st!=NULL)
int pop(void); {
printf("%d ," ,st->item);
void main(void) st=st->next;
}
{ int opt,ch,y; st=t;
clrscr(); }
do void push(int x)
{ {
clrscr(); struct stack *r;
printf("\n1. Push\n"); r=(struct stack*)malloc(sizeof(struct stack));
printf("\n2. Pop\n"); r->item=x;
printf("\n3. Print\n"); r->next=st;
printf("\n4. Exit\n"); st=r;
printf("\n\n\t Enter your Choice\n"); top=st;
scanf("%d",&opt); return;
}
switch(opt)
{
case 1:
printf("\nEnter item to Push\n");
scanf("%d", &y);
push(y);
break;
case 2:
int pop(void)
{
struct stack *r;
int x;
r=st;
if(top==NULL)
{
printf("Empty Stack");
exit(0);
}
else
{
r=st->next;
x=st->item;
free(st);
st=r;
top=st;
}
return x;
}