← 返回 optiver 的题目列表Design a Circular Queue
类型:online_judge
Design a circular queue with the following operations:
enQueue(value): Inserts an integer into the circular queue. Returns true if the operation is successful.
deQueue(): Deletes an element from the circular queue. Returns true if the operation is successful.
Front(): Gets the front item from the queue. If the queue is empty, return -1.
Rear(): Gets the last item from the queue. If the queue is empty, return -1.
isEmpty(): Checks whether the circular queue is empty or not.
isFull(): Checks whether the circular queue is full or not.
Note:
All inputs are in the range from 0 to 1000.
The number of operations will not exceed 1000.
You cannot use the built-in Queue library.
Example:
Input:
5
["enQueue", "enQueue", "enQueue", "enQueue", "Rear", "isFull", "deQueue", "enQueue", "Rear"]
[[1], [2], [3], [4], [], [], [], [4], []]
Output:
[true, true, true, false, 3, true, true, true, 4]
Example
Input
5
["enQueue", "enQueue", "enQueue", "enQueue", "Rear", "isFull", "deQueue", "enQueue", "Rear"]
[[1], [2], [3], [4], [], [], [], [4], []]
Output
[true, true, true, false, 3, true, true, true, 4]