A Simple program for implementing Linked Stack
Code: Cpp
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct node
{
int data;
struct node *link;
};
struct node *top=NULL,*temp;
void main()
{
int choice,data;
clrscr();
while(1)//infinite loop is used to insert/delete infinite number of nodes
{
printf("\n1.Push\n2.Pop\n3.Display\n4.Exit\n");
printf("\nEnter ur choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter a node data :");
scanf("%d",&data);
temp->data=data;
temp->link=top;
top=temp;
break;
case 2:
if(top!=NULL)
{
printf("The poped element is %d",top->data);
top=top->link;
}
else
{
printf("\nStack Underflow");
}
break;
case 3:
temp=top;
if(temp==NULL)
{
printf("\nStack is empty\n");
}
while(temp!=NULL)
{
printf("->%d->",temp->data);
temp=temp->link;
}
break;
case 4:
exit(0);
}
}
}



