← 返回 linkedin 的题目列表Implement a Queue using Stacks
类型:online_judge
Implement a queue using two stacks. Provide the following methods: void enqueue(int element) to add an element to the end of the queue; int dequeue() to remove and return the element at the front of the queue; int peek() to return the element at the front of the queue without removing it; boolean isEmpty() to check if the queue is empty. Strive for optimal time efficiency. Provide test cases.
Example
Input
1
enqueue 1
enqueue 2
dequeue
peek