#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 10
struct Stack {
int arr[MAX_SIZE];
int top;
};
void initialize(struct Stack *s) {
s->top = -1;
}
int isEmpty(struct Stack *s) {
return (s->top == -1);
}
int isFull(struct Stack *s) {
return (s->top == MAX_SIZE - 1);
}
void push(struct Stack *s, int value) {
if (isFull(s)) {
printf("Stack overflow\n");
return;
}
s->arr[++s->top] = value;
}
int pop(struct Stack *s) {
if (isEmpty(s)) {
printf("Stack underflow\n");
exit(1);
}
return s->arr[s->top--];
}
int peek(struct Stack *s) {
if (isEmpty(s)) {
printf("Stack is empty\n");
exit(1);
}
return s->arr[s->top];
}
int main() {
struct Stack stack;
initialize(&stack);
push(&stack, 10);
push(&stack, 20);
push(&stack, 30);
printf("Top element: %d\n", peek(&stack));
printf("Popped element: %d\n", pop(&stack));
printf("Top element after pop: %d\n", peek(&stack));
return 0;
}