
Problem
Solution
Submissions
Circular Queue with Dynamic Resizing
Certification: Intermediate Level
Accuracy: 0%
Submissions: 1
Points: 12
Write a C# program to implement a circular queue with dynamic resizing. A circular queue is a linear data structure that follows the FIFO (First In First Out) principle. The operations should include Enqueue, Dequeue, Front, Rear, IsEmpty, IsFull, and resize when needed.
Example 1
- Input:
MyCircularQueue q = new MyCircularQueue(3);
q.Enqueue(1);
q.Enqueue(2);
q.Enqueue(3);
q.Enqueue(4);
q.Dequeue();
q.Enqueue(5);
q.Front(); - Output:
true // Enqueue 1
true // Enqueue 2
true // Enqueue 3
true // Enqueue 4 (triggers resize)
1 // Dequeue returns 1
true // Enqueue 5
2 // Front value
Example 2
- Input:
MyCircularQueue q = new MyCircularQueue(5);
q.Enqueue(10);
q.Enqueue(20);
q.Dequeue();
q.Dequeue();
q.IsEmpty(); - Output:
true // Enqueue 10
true // Enqueue 20
10 // Dequeue returns 10
20 // Dequeue returns 20
true // queue is empty
Constraints
- 1 <= capacity <= 1000
- 0 <= value <= 10^4
- At most 3000 calls will be made to Enqueue, Dequeue, Front, Rear, IsEmpty, and IsFull
- Time Complexity: O(1) average time per operation, O(n) for resize
- Space Complexity: O(n), where n is the capacity of the queue
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use an array to implement the circular queue
- Keep track of front and rear indices
- Implement Enqueue, Dequeue, Front, Rear, IsEmpty, and IsFull operations
- When the queue is full, resize it by creating a new array with double capacity
- Properly handle wrapping around the end of the array