C#LeetCode刷题之#232-用栈实现队列​​​​​​​​​​​​​​（Implement Queue using Stacks）

push(x) — 将一个元素放入队列的尾部。
pop() — 从队列首部移除元素。
peek() — 返回队列首部的元素。
empty() — 返回队列是否为空。

MyQueue queue = new MyQueue();

queue.push(1);

queue.push(2);

queue.peek();  // 返回 1

queue.pop();   // 返回 1

queue.empty(); // 返回 false

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.

MyQueue queue = new MyQueue();

queue.push(1);

queue.push(2);

queue.peek();  // returns 1

queue.pop();   // returns 1

queue.empty(); // returns false

Notes:

You must use only standard operations of a stack — which means only push to top, peek/pop from top, size, 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).

```public class Program {

public static void Main(string[] args) {
var queue = new MyQueue();

queue.Push(1);
queue.Push(2);
queue.Push(3);

Console.WriteLine(queue.Peek());
Console.WriteLine(queue.Pop());
Console.WriteLine(queue.Empty());

}

public class MyQueue {

private Stack<int> _stack = null;

public MyQueue() {
_stack = new Stack<int>();
}

public void Push(int x) {
//基本思路是反转原栈
var stack = new Stack<int>();
stack.Push(x);
var reverse = _stack.Reverse().ToList();
foreach(var elemet in reverse) {
stack.Push(elemet);
}
_stack = stack;
}

public int Pop() {
return _stack.Pop();
}

public int Peek() {
return _stack.Peek();
}

public bool Empty() {
return _stack.Count == 0;
}

}

}```

```1
1
False```

(5)