Stack Linked List
Stack Linked List
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;
}