#include <stdio.h>
#include <stdbool.h>
#define MAX_SIZE 100
char items[MAX_SIZE];
int top = -1;
void initialize() {
top = -1;
}
bool isFull() {
return top == MAX_SIZE - 1;
}
bool isEmpty() {
return top == -1;
}
// You are using GCC
void push(char value) {
top = top + 1;
items[top] = value;
printf("Pushed: %c\n", value);
}
char pop() {
if (top == -1) {
printf("Stack is empty. Nothing to pop.");
return 0;
}
char popped = items[top];
top = top - 1;
printf("Popped: %c\n", popped);
return popped;
}
void display() {
if (top == -1) {
printf("Stack is empty.");
} else {
printf("Stack elements: ");
for (int i = top; i > -1; i--) {
printf("%c ", items[i]);
}
}
printf("\n");
}
int main() {
initialize();
int choice;
char value;
while (true) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf(" %c", &value);
push(value);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice\n");
}
}
return 0;
}