-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueUsingStacks.cs
More file actions
66 lines (55 loc) · 1.49 KB
/
Copy pathQueueUsingStacks.cs
File metadata and controls
66 lines (55 loc) · 1.49 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Algorithms.Problem.Queues
{
[TestClass]
public class QueueUsingStacks
{
private Stack<int> auxillaryStack = new Stack<int>();
private Stack<int> realStack = new Stack<int>();
public void DequeueMoreCost()
{
}
public void EnqueueMoreCost(int value)
{
if (!realStack.Any())
{
realStack.Push(value);
return;
}
while(realStack.Any())
{
int getValue = realStack.Pop();
auxillaryStack.Push(getValue);
}
realStack.Push(value);
while(auxillaryStack.Any())
{
int getValue = auxillaryStack.Pop();
realStack.Push(getValue);
}
}
public int Dequeue()
{
if (!realStack.Any())
{
return -1;
}
return realStack.Pop();
}
[TestMethod]
public void TestQueueUsingStack()
{
this.EnqueueMoreCost(1);
this.EnqueueMoreCost(2);
this.EnqueueMoreCost(3);
Assert.AreEqual(1, this.Dequeue());
Assert.AreEqual(2, this.Dequeue());
Assert.AreEqual(3, this.Dequeue());
}
}
}