← Back

Stacks & Queues

Simulation Speed:1x

Stack Operations (LIFO)

A stack is a Last-In-First-Out (LIFO) data structure where elements are added and removed from the same end, called the top. Think of it like a stack of plates - you can only add or remove from the top.

1
2
3
← Top

Operations Log:

C Code Example:

// Stack implementation using array
#define MAX_SIZE 100
struct Stack {
int items[MAX_SIZE];
int top;
};
// Push operation
void push(struct Stack* stack, int value) {
if (stack->top == MAX_SIZE - 1) {
printf("Stack overflow\n");
return;
}
stack->items[++stack->top] = value;
}
// Pop operation
int pop(struct Stack* stack) {
if (stack->top == -1) {
printf("Stack underflow\n");
return -1;
}
return stack->items[stack->top--];
}

made by billy | source code | @b9llach