Data Structures & Algorithms
Checking If A Stack Is Empty
StacksFor the isEmpty function, we simply check if top is equal to -1. If it is, the stack has no items, so we return true. Otherwise, we return false, meaning the stack contains at least one item. This makes it a quick and straightforward way to check if the stack is empty.
Members only
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 42 more lessons in Data Structures & Algorithms.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.