Queue Visualizer
What is the isFull Operation?
The isFull operation checks whether a queue has reached its maximum capacity in fixed-size implementations. It returns true if no more elements can be added (queue is full) and false if space remains. This operation is crucial for preventing overflow in array-based queue implementations.
How Does It Work?
The isFull operation examines the queue's capacity and current state:
Example scenarios (for a queue with capacity 3):
Note: Dynamic implementations (like linked lists) typically don't need this operation as they can grow indefinitely.
Example scenarios (for a queue with capacity 3):
- Full Queue: [10, 20, 30]
- isFull() → returns true
- Non-full Queue: [10, 20]
- isFull() → returns false
Note: Dynamic implementations (like linked lists) typically don't need this operation as they can grow indefinitely.
Implementation Details
Different approaches to check if a queue is full:
- Linear Array Implementation:
- Check if rear == capacity - 1
- Simple but wastes space when front ≠ 0
- Circular Array Implementation:
- Check if (rear + 1) % capacity == front
- More space-efficient
- Size Counter Approach:
- Maintain a size variable
- Check if size == capacity
Algorithm Steps
For circular array implementation:
- Calculate next rear position: (rear + 1) % capacity
- Compare with front position
- If equal, return true (queue is full)
- Else return false (space available)
Time Complexity
The isFull operation always runs in O(1) constant time because:
- It only requires simple pointer arithmetic and comparison
- No iteration through elements is needed
- Performance is independent of queue size
Practical Usage
isFull is essential in:
- Bounded buffer problems
- Producer-consumer scenarios
- Memory-constrained systems
- Before enqueue operations to prevent overflow
Special Cases
- Dynamic Queues: Always return false (no capacity limit)
- Empty Full Queue: Possible when capacity = 0
- Edge Cases: When front = 0 and rear = capacity - 1
The isFull operation is critical for robust queue implementations in fixed-capacity scenarios, ensuring data integrity by preventing buffer overflow conditions in system programming and embedded applications.
Max size: 5 items
Queue is empty
FrontRear
Queue is empty!
Queue Implementation (isFull Function Only)
// Array Queue isFull in JavaScript
class ArrayQueue {
constructor(capacity) {
this.arr = new Array(capacity);
this.front = -1;
this.rear = -1;
this.capacity = capacity;
}
isFull() {
return (this.rear + 1) % this.capacity === this.front;
}
}