#include<stdio.h>
#include<conio.h>
#define max 5
int stack[max];
int top = -1;
void menu(void);
void push(int number_to_insert);
int pop(void);
void print(void);
void main()
{
int choice, num;
int flag = 1;
while(flag)
{
menu();
printf("\nEnter Choice = ");
scanf("%d",&choice);
clrscr();
switch(choice)
{
case 1: printf("Enter number you want to push in the stack: ");
scanf("%d",&num);
push(num);
getch();
break;
case 2: num = pop();
getch();
break;
case 3: print();
break;
case 9: flag = 0;
printf("Exit Program\n");
break;
default: printf("Invalid choice\n");
}
}
}
void menu(void)
{
clrscr();
printf(" Menu of Stack \n");
printf("1 : push\n");
printf("2 : pop\n");
printf("3 : print\n");
printf("9 : Exit Program\n");
}
void push(int number_to_insert)
{
if((top + 1) == max)
printf("Stack is full !!!\n");
else
{
top = top + 1;
stack[top] = number_to_insert;
printf("push complete.\n");
}
}
int pop(void)
{
int number_to_remove;
if(top < 0)
printf("Stack is empty !!!\n");
else
{
number_to_remove = stack[top];
printf("you pop the number %d\n",number_to_remove);
stack[top] = NULL;
top = top - 1;
return number_to_remove;
}
return 0;
}
void print(void)
{
int i;
for(i=(max-1);i>=0;i--)
printf("array [%d] of stack = %d\n",i,stack);
printf("\n\npress any key to continue.\n");
getch();
}[/b]