#include #define capacity 5 int stack[capacity]; int top=-1; int isFull() { if(top == capacity-1) { return 1; } else { return 0; } } int isEmpty() { if(top == -1) { return 1; } else { return 0; } } void push(int num) { if(isFull()) { printf("Stack is Overflowed\n"); } else { top++; stack[top] = num; printf("Entered number : %d is pushed\n",num); } } int pop() { if(isEmpty()) { return 0; } else { return stack[top--]; } } void peek() { if(isEmpty()) { printf("Stack is Empty\n"); } else { printf("Peak Element : %d\n",stack[top]); } } void traverse() { if(isEmpty()) { printf("Stack is Empty\n"); } else { int i; printf("The Elements are : "); for(i=0; i<=top; i++) { printf("%d ",stack[i]); } printf("\n"); } } int main() { int select,num; while(1) { printf("1. Push \n"); printf("2. Pop \n"); printf("3. Peek \n"); printf("4. Traverse \n"); printf("5. Quit \n"); printf("\nEnter your choice :\n"); scanf("%d",&select); switch(select) { case 1 : printf("Enter your element :"); scanf("%d",&num); push(num); break; case 2 : num = pop(); if(num == NULL) { printf("Stack is Empty\n"); } else { printf("Poped item is %d\n",num); } break; case 3 : peek(); break; case 4 : traverse(); break; case 5 : exit(0); default : printf("Invalid input\n\n"); } } }