Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
#include
#define MAX 3 int stack[MAX]; int top = -1; void push(int value) { if (top == MAX - 1) { printf("Overflow! Cannot push %d\n", value); return; } top++; stack[top] = value; printf("Pushed %d\n", value); } int pop() { if (top == -1) { printf("Underflow! The stack is empty\n"); return -1; } int value = stack[top]; top--; printf("Popped %d\n", value); return value; } int main() { push(1); push(2); push(3); push(4); // The stack is full pop(); pop(); pop(); pop(); // The stack is empty return 0; }
Pushed 1
Pushed 2
Pushed 3
Overflow! Cannot push 4
Popped 3
Popped 2
Popped 1
Underflow! The stack is empty