-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.cs
49 lines (44 loc) · 842 Bytes
/
Queue.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
44
45
46
47
48
49
using System;
using System.Collections;
using System.Text;
namespace ConsoleApp19
{
class Queue
{
public Stack s1 = new Stack();
public Stack s2 = new Stack();
public void EnQueue(int x)
{
while (s1.Count > 0)
{
s2.Push(s1.Pop());
}
s1.Push(x);
while (s2.Count > 0)
{
s1.Push(s2.Pop());
}
}
public int Dequeue()
{
if (s1.Count == 0)
{
Console.WriteLine("Q is Empty");
}
int x = (int)s1.Peek();
s1.Pop();
return x;
}
public static void Main()
{
Queue q = new Queue();
q.EnQueue(1);
q.EnQueue(2);
q.EnQueue(3);
q.EnQueue(4);
Console.WriteLine(q.Dequeue() + " ");
Console.WriteLine(q.Dequeue() + " ");
Console.WriteLine(q.Dequeue());
}
}
}