



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Program #include<stdio.h> #include<stdlib.h> int stack[100],i,input,len,init,top=-1; void push(); void pop(); void peek(); void display(); void quit(); void main() { printf("\nEnter Total length of Stack:"); scanf("%d",&len); printf("\nHow many element do you want to insert:"); scanf("%d",&init); for(i=0;i<init;i++) { printf("\nEnter the Element:"); scanf("%d",&input); top+=1;
stack[top]=input; } printf("\n1:Push\t2:Pop\t3:Peek\t4:display\t5:Quit"); while(1){
scanf("%d",&input); switch(input) { case 1: push(); break; case 2: pop(); break; case 3: peek(); break; case 4: display(); break; case 5: quit(); break;
void peek(){ if(top == -1){ printf("\nStack is empty");} else{ printf("\nPeek element is %d",stack[top]);} } void display(){ if(top == -1) printf("\nStack is empty"); else { printf("\nElements in Stack:"); for(i=0;i<=top;i++){ printf("%d ",stack[i]);} printf("\n"); } } void quit(){ exit(0); }
Enter the Element: Enter the Element: Enter a number to perform operation: