Here it is....
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *link;
};
void push(node **t, int item)
{
node *temp;
temp=(node *)malloc(sizeof(node));
temp->data=item;
if(*t==NULL)
*t=temp;
else
{
temp->link=*t;
*t=temp;
}
}
void pop(node **t)
{
node *temp;
if(*t==NULL)
printf("\nStack Underflow\n");
else
{
temp=*t;
(*t)=(*t)->link;
free(temp);
}
}
void display(node **t)
{
if(*t==NULL)
printf("\nEmpty Stack\n");
else
{
while(*t!=NULL)
{
printf("\n%d\n", (*t)->data);
*t=(*t)->link;
}
}
}
void main()
{
node *top;
int i,n;
char c;
printf("\nWelcome\n");
do
{
printf("\nEnter 1 for PUSH, 2 for POP, 3 for DISPLAY\t");
scanf("%d", &i);
switch(i)
{
case 1:
{
printf("\nEnter the value to be pushed=");
scanf("%d", &n);
push(&top,n);
break;
}
case 2:
{
pop(&top);
break;
}
case 3:
{
display(&top);
break;
}
default:
{
printf("\nYou are given no other choice than 1,2 and 3\n");
printf("\nPlease try again\n");
break;
}
}
printf("\nDo you wish to continue?[y/n]\t");
c=getch();
printf("\n");
}while(c=='y'||c=='Y');
printf("\nThank You, Press Any Key To Exit\n");
getch();
}



