IsEmpty() -> boolean
Checks if the data structure has no elements. For a Stack, `top == -1`. For a Queue, `front == -1` or `front > rear`. You MUST call this before popping/dequeuing.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Before adding or removing elements from Stacks and Queues, you must perform state checks to prevent crashing your program with Overflow or Underflow errors.
Checks if the data structure has no elements. For a Stack, `top == -1`. For a Queue, `front == -1` or `front > rear`. You MUST call this before popping/dequeuing.
Checks if the data structure has reached its maximum capacity. For an array Stack, `top == size - 1`. For an array Queue, `rear == size - 1`. You MUST call this before pushing/enqueuing.
If you implement your Stack or Queue using a Linked List, `IsFull()` is practically always `false` (until your computer runs out of RAM!). `IsEmpty()` is checked via `head == null`.