-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
43 lines (41 loc) · 890 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections;
namespace ImplementQueueUsingStacks
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
public class MyQueue
{
private Stack<int> queue;
public MyQueue()
{
queue = new Stack<int>();
}
public void Push(int x)
{
var temp = new Stack<int>();
while (queue.Count != 0)
temp.Push(queue.Pop());
queue.Push(x);
while (temp.Count != 0)
queue.Push(temp.Pop());
}
public int Pop()
{
return queue.Pop();
}
public int Peek()
{
return queue.Peek();
}
public bool Empty()
{
return queue.Count == 0;
}
}
}