Stack
A Stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Elements are added and removed from the same end (top). Common operations include push, pop, and peek.
Stack Visualization
Stack Visualizer V3
A cinematic, high-fidelity simulation of a LIFO data structure with synchronized motion, code, memory and feedback systems.
Size
0
Top
—
Mode
LIVE
Removed
—
Stack chamber is empty
Insert a value using Push to begin the sequence.
Synchronized Logic
Complexity
O(1) for push/pop/peekO(n)Pseudocode
class Stack:
function push(item):
stack.append(item)
function pop():
if stack is empty:
return error
return stack.remove_last()
function peek():
return stack[last_index]Related Algorithms
Queue
A Queue is a linear data structure that follows the First-In-First-Out (FIFO) principle. Elements are added at the rear and removed from the front. Common operations include enqueue and dequeue.
Linked List
A Linked List is a linear data structure where elements are stored in nodes, and each node points to the next node. It allows dynamic memory allocation and efficient insertion/deletion operations.