juniorStacks

How do you check if a Stack is empty?

Updated Apr 28, 2026

Short answer

Check if the top pointer is -1 (array) or null (linked list).

Deep explanation

Stacks are fundamental in computer science for managing nested or ordered data. Check if the top pointer is -1 (array) or null (linked list). They ensure that the last item processed is the first one returned, maintaining a strict temporal order.

Real-world example

Back button functionality in a web browser.

Common mistakes

  • Forgetting to check for emptiness before popping, causing a runtime error.

Follow-up questions

  • What is the space complexity?

More Stacks interview questions

View all →