You are on page 1of 4

PROGRAM CODING:

#include<stdio.h>
#include<alloc.h>
#include<conio.h>
#include<stdlib.h>
struct stack
{
int data;
struct stack *link;
};
typedef struct stack node;
node *top=NULL,*t;
void push();
void pop();
void disp();
void main()
{
int c;
char ch;
while(1)
{
clrscr();
printf("\n1. Push ");
printf("\n2. POP");
printf("\n3. Display ");
printf("\n4. Exit ");
printf("\nEnter Your Choice ");
scanf("%d",&c);
switch(c)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
disp();
break;
case 4:
exit(0);
default:
printf("\nInvalid Choice ");
}
getch();
}
}
void push()
{
t=(node*)malloc(sizeof(node*));
printf("\nEnter the Data value ");
scanf("%d",&t->data);
t->link=NULL;
if(top==NULL)
top=t;
else
{
t->link=top;
top=t;
}
}
void pop()
{
if(top==NULL)
printf("\nStack Empty");
else
{
t=top;
top=top->link;
printf("\nNode Deleted is %d",t->data);
free(t);
}
}
void disp()
{
if(top==NULL)
printf("\nStack Empty");
else
{
t=top;
printf("\n");
while(t!=NULL)
{
printf("->%d",t->data);
t=t->link;}}}
OUTPUT:

You might also like