Codacoda
Back to Academy

stacks queues

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, called the 'top'. Think of it like a stack of plates - you can only add or remove from the top.

Use Cases

  • Function call management (call stack)
  • Undo/redo operations
  • Expression evaluation and syntax parsing

Complexity Analysis

MetricBestAverageWorst
TimeO(1)O(1)O(1)
SpaceO(n)

Visualization

bottom

Speed:1x
Empty stackStep 1 / 10

Implementation

Output

Click "Run Code" to see output...