#include<stdio.h>
#include<conio.h>
#include<process.h>
#define STACK_SIZE 100
struct stack
{
int top; int items[STACK_SIZE];
};
struct stack s;
int empty(struct stack *ps)
{
if(ps->top==-1)
{
printf("Empty");
return 1;
}
else
return 0;
}
int pop(struct stack *ps)
{
int x;
if(empty(ps))
{
printf("underflow");
return 0;
}
x=ps->items[ps->top];
ps->top--;
return x;
}
void push(struct stack *ps,int x)
{
if(ps->top==STACK_SIZE-1)
{
printf("overflow");
return;
}
ps->top++;
ps->items[ps->top]=x;
}
void display(struct stack *ps)
{
int t=ps->top;
if(empty(ps))
{
printf("stack empty");
return;
}
while(t!=-1)
{
printf("\n %d",ps->items[t]);
t--;
}}
void main()
{
int choice,x;
struct stack s;
clrscr();
s.top=-1;
do
{
printf("\n Insert 1:PUSH");
printf("\n Insert 2:POP");
printf("\n Insert 3:DISPLAY");
printf("\n Insert 4:EXIT");
printf("\n Enter ur Choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter element to insert");
scanf("%d",&x);
push(&s,x);
break;
case 2:
x=pop(&s);
if(x)
printf("\n Deleted element is: %d",x);
break;
case 3:
display(&s);
break;
case 4:
exit(0);
}}
while(choice!=4);
getch();
}
OUTPUT-

#include<conio.h>
#include<process.h>
#define STACK_SIZE 100
struct stack
{
int top; int items[STACK_SIZE];
};
struct stack s;
int empty(struct stack *ps)
{
if(ps->top==-1)
{
printf("Empty");
return 1;
}
else
return 0;
}
int pop(struct stack *ps)
{
int x;
if(empty(ps))
{
printf("underflow");
return 0;
}
x=ps->items[ps->top];
ps->top--;
return x;
}
void push(struct stack *ps,int x)
{
if(ps->top==STACK_SIZE-1)
{
printf("overflow");
return;
}
ps->top++;
ps->items[ps->top]=x;
}
void display(struct stack *ps)
{
int t=ps->top;
if(empty(ps))
{
printf("stack empty");
return;
}
while(t!=-1)
{
printf("\n %d",ps->items[t]);
t--;
}}
void main()
{
int choice,x;
struct stack s;
clrscr();
s.top=-1;
do
{
printf("\n Insert 1:PUSH");
printf("\n Insert 2:POP");
printf("\n Insert 3:DISPLAY");
printf("\n Insert 4:EXIT");
printf("\n Enter ur Choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter element to insert");
scanf("%d",&x);
push(&s,x);
break;
case 2:
x=pop(&s);
if(x)
printf("\n Deleted element is: %d",x);
break;
case 3:
display(&s);
break;
case 4:
exit(0);
}}
while(choice!=4);
getch();
}
OUTPUT-