Untitled
unknown
plain_text
a month ago
1.8 kB
1
Indexable
Never
#include<stdio.h> int stack[100],i,j,choice=0,n,top=-1; void push(); void pop(); void show(); void exit(); void main() { printf("***********Stack operations using array **********"); printf("\n.................+++++++++++..............\n"); printf("\n Enter the size of stack : "); scanf("%d",&n); while(choice!=4) { printf("Choose one from the below options+++ : \n "); printf("\n 1.push \n 2.pop \n 3.Show \n 4.Exit"); printf("\n Enter your Choice : \n "); scanf("%d",&choice); switch(choice) { case 1: { push(); break; } case 2: { pop(); break; } case 3: { show(); break; } case 4: { exit(); printf("\n Exiting....\n"); break; } default: { printf("Please Enter from 1 to 4"); } }; } } void push() { int val; if(top==n-1) printf("\n Overflow"); else { printf("Enter The Value?"); scanf("%d",&val); top=top+1; stack[top]=val; } } void pop() { if(top==-1) printf("Underflow\n"); else top=top-1; } void show() { for(i=top;i>=0;i--) { printf("%d\n",stack[i]); } if(top==-1) { printf("Stack is Empty\n"); } }
Leave a Comment