#include <stdio.h> #define MAX_SIZE 10cx fdk struct Stack { int arr[MAX_SIZE]; int top; }; // Function to display the current state of the stack void display(struct Stack *stack) { printf("Stack:\n"); for (int i = MAX_SIZE - 1; i >= 0; i--) { if (i <= stack->top) { printf("| %3d |\n", stack->arr[i]); } else { printf("| |\n"); } printf("-------\n"); } printf("\n"); } // Function to initialize the stack void initialize(struct Stack *stack) { stack->top = -1; } // Function to check if the stack is empty int isEmpty(struct Stack *stack) { return stack->top == -1; } // Function to check if the stack is full int isFull(struct Stack *stack) { return stack->top == MAX_SIZE - 1; } // Function to push an element onto the stack void push(struct Stack *stack, int value) { if (isFull(stack)) { printf("Stack overflow\n"); } else { stack->arr[++stack->top] = value; printf("%d pushed to stack\n", value); // Display the current state of the stack display(stack); } } // Function to pop an element from the stack int pop(struct Stack *stack) { if (isEmpty(stack)) { printf("Stack underflow\n"); return -1; // Assuming -1 represents an error or an invalid value } else { // Display the element being popped printf("%d popped from stack\n", stack->arr[stack->top]); return stack->arr[stack->top--]; } } int main() { struct Stack myStack; initialize(&myStack); push(&myStack, 10); push(&myStack, 20); push(&myStack, 30); printf("Top element is %d\n", myStack.arr[myStack.top]); pop(&myStack); pop(&myStack); printf("Is the stack empty? %s\n", isEmpty(&myStack) ? "Yes" : "No"); return 0; }