← 返回 meta 的题目列表Fixed Size Queue Implementation
类型:online_judge
meta
Implement a fixed-size queue. The queue should support the following operations: enqueue, dequeue, peek (retrieve the front element), and check if the queue is empty. Ensure that the implemented queue disallows enqueue operations when full and returns null or a specific error indicator when attempting to perform operations on the front element if the queue is empty.
Provide test cases:
Initialize a queue with a fixed size of 3.
Enqueue elements [1, 2, 3], then attempt to enqueue 4, which should fail.
Peek the front element, expecting 1.
Dequeue an element, then enqueue 4.
Check the queue state.
Scale of operations: up to 100 operations in total.
Example
Input
3
enqueue 1
enqueue 2
enqueue 3
enqueue 4
peek
dequeue
enqueue 4
peek