stack
stack
h>
#include<stdbool.h>
int stack[100];
int top = -1;
int size = 0;
bool isEmpty() {
if(top == -1)
return true;
else
return false;
}
bool isFull() {
if(top + 1 == size)
return true;
else
return false;
}
int pop() {
int p = stack[top--];
return p;
}
void display() {
int i;
for(i = top; i >= 0; i--)
printf("\n%d", stack[i]);
}
void main() {
do {
printf("\nEnter 1 to push \nEnter 2 to pop \nEnter 3 to peek \nEnter 4 to
display the stack \nEnter 5 to check size \nEnter 6 to exit \n\nchoice: ");
int choice;
scanf("%d", &choice);
if(choice == 1) {
int data;
printf("\nEnter the data to pushed: ");
scanf("%d", &data);
push(data);
}
else if(choice == 2) {
if(isEmpty())
printf("\nStack Underflow!");
else {
int popped = pop();
printf("\nPopped element = %d", popped);
}
}
else if(choice == 3) {
printf("\nTop of stack = %d", stack[top]);
}
else if(choice == 4) {
display();
}
else if(choice == 5) {
printf("\nSize = %d", top + 1);
}
else if(choice == 6) {
return;
}
else {
printf("\nInvalid choice!!!");
}
}while(true);
}