# leetcode刷题， 总结，记录，备忘 232

leetcode232

### Implement Queue using Stacks

Implement the following operations of a queue using stacks.

• push(x) -- Push element x to the back of queue.
• pop() -- Removes the element from in front of queue.
• peek() -- Get the front element.
• empty() -- Return whether the queue is empty.
Notes:
• You must use only standard operations of a stack -- which means only push to toppeek/pop from topsize, and is empty operations are valid.
• Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.
• You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).

class Queue {
public:
// Push element x to the back of queue.
void push(int x) {
int temp;
while (s.size())
{
t.push(s.top());
s.pop();
}
s.push(x);
while (t.size())
{
temp = t.top();
t.pop();
s.push(temp);
}
}

// Removes the element from in front of queue.
void pop(void) {
s.pop();
}

// Get the front element.
int peek(void) {
return s.top();
}

// Return whether the queue is empty.
bool empty(void) {
return s.size() == 0;
}
stack<int> s;
stack<int> t;
};

#### Leetcode_232_Implement Queue using Stacks

2015-09-12 11:01:23

#### LeetCode 232： Implement Queue using Stacks

2015-07-07 19:35:06

#### 【LeetCode-232】 Implement Queue using Stacks(C++)

2016-09-03 17:37:16

#### LeetCode 232. 用栈实现队列

2018-04-21 00:29:18

#### 【LeetCode OJ 232】Implement Queue using Stacks

2016-02-25 21:02:13

#### leetcode 232:Implement Queue using Stacks

2015-07-07 04:48:38

#### Leetcode 第232题 Implement Queue using Stacks

2015-11-28 00:10:16

#### 剑指Offer面试题7 & Leetcode232

2017-05-07 17:45:59

#### LeetCode-232.Implement Queue using Stacks

2016-06-13 22:25:04

#### leetcode-232-Implement Queue using Stacks

2015-08-03 17:29:45