Skip to content

Commit b65a2c4

Browse files
committed
Stubbed out MyStack class
Set up debug_stack object to see if my stack implementation behaves correctly in comparison with an actual stack
1 parent 4f3d316 commit b65a2c4

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

Assignment5/Problem3.cs

+29-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void RunInteractiveTesting()
4545

4646
}
4747

48-
public class MyStack<T>
48+
public class MyStack<T> where T : IEquatable<T>
4949
{
5050
private readonly Queue<T> q1_above;
5151
private readonly Queue<T> q2_below;
@@ -61,11 +61,38 @@ public MyStack()
6161
debug_stack = new Stack<T>();
6262
}
6363

64+
public T Pop()
65+
{
66+
if (q1_above.Count + q2_below.Count == 0)
67+
throw new InvalidOperationException("Stack is empty.");
68+
69+
// TODO: ACTUALL IMPLEMENT POP
70+
var item = q1_above.Dequeue();
71+
72+
73+
74+
var itemPoppedFromActualStack = debug_stack.Pop();
75+
76+
if (item.Equals(itemPoppedFromActualStack) == false)
77+
throw new Exception("Item popped from actual stack was" +
78+
$" {itemPoppedFromActualStack}, item you popped was {item}");
79+
80+
return default;
81+
}
82+
83+
public void Push(T item)
84+
{
85+
// TODO: ACTUALLY IMPLEMENT PUSH
86+
87+
88+
debug_stack.Push(item);
89+
}
90+
91+
6492
public string Debug_View
6593
{
6694
get
6795
{
68-
6996
// Using screen coordinates convention for
7097
// the visualization: 0,0 is at upper left
7198

0 commit comments

Comments
 (0)