#include<stdio.h> #include<stdlib.h> int stack[100]; int top=-1; void push(); void pop(); void peek(); void Display(); int main(){ int x; while(x!=5){ printf("\n\n\nWelcome To stack\n\n"); printf("\n1. Push\n"); printf("2. Pop\n"); printf("3. Peek\n"); printf("4. Display\n"); printf("5. Exit\n"); scanf("%d",&x); printf("\n\n\n"); switch(x){ case 1: push(); break; case 2: pop(); break; case 3: peek(); break; case 4: Display(); break; case 5: exit(0); default: printf("Enter valid choice"); } } return 0; } void push(){ int x; printf("Enter Data "); scanf("%d",&x); top++; stack[top]=x; } void pop(){ int item; if(top==-1){ printf("underflow"); } else{ item=stack[top]; top--; printf("%d deleted\n",item); } } void peek(){ if(top==-1){ printf("underflow"); } else{ printf("\n%d\n",stack[top]); } } void Display(){ int i; for(i=top;i>=0;i--){ printf(" %d \n\n",stack[i]); } }
HTML
Tech News
Ad
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment