DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Tools
  3. Algorithm Visualizer
  4. Stack (Push/Pop)

Stack (Push/Pop)

Data Structureseasy#12

LIFO data structure — push and pop from the top

Ready

Step 1 of 0

Speed

Input Data

Comma-separated numbers (0-999). Min 2 values.

Algorithm Code

1class Stack {
2 constructor() { this.items = []; }
3 push(item) { this.items.push(item); }
4 pop() { return this.items.pop(); }
5 peek() { return this.items[this.items.length-1]; }
6 isEmpty() { return this.items.length === 0; }
7 size() { return this.items.length; }
8}
Best

O(1)

Average

O(1)

Worst

O(1)

Space

O(n)

About Stack (Push/Pop)

A Stack is a LIFO (Last In, First Out) data structure. Elements are added (push) and removed (pop) from the same end (top). Used in function call stacks, expression evaluation, undo operations, DFS traversal, and bracket matching.

Time Complexity: Best: O(1), Average: O(1), Worst: O(1). Space: O(n).

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.