#include<stdio.h>
#include<conio.h>
#include<process.h>
#define MAX 50

struct st { int top; int ele[MAX]; } *s;
int empty(struct st *s)
  { return (s->top==-1); }
void display(struct st *s)
{
 int x; x=s->top;
 if(empty(s))
 {  printf("\nStack is empty"); getch(); }
 else
   printf("\nThe elements of the stack are\n");
  while(x>-1)  printf("\n%d", s->ele[x--]);
  getch();
 }
void push(struct st *s, int x)
  { s->top++; s->ele[s->top]=x; }
int pop(struct st *s)
  {  return s->ele[s->top--];}

 void main()
{
 int x,n;s->top=-1;
 do
 {
  clrscr();
  printf("\n\t\t1.Pop\n2.Push\n3.Display\n4.Exit");
  printf("\n\nEnter your choice: ");
  scanf("%d", &n);
  switch(n)
  {
   case 1 : if(empty(s))
	    printf("\nStack empty");
	    else  printf("\n Popped element =%d", pop(s));  break;
   case 2 : printf("Enter the element\n");
	    scanf("%d", &x);
	    if(s->top==MAX-1)
	    printf("\nStack overflow");
	    else push(s,x);  break;
   case 3 : display(s); break;
   case 4 : printf("Exiting. Press any key.");
	    getch();  exit(0);
  }
 } while(1==1);
}


