File tree 1 file changed +29
-2
lines changed
1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ public static void RunInteractiveTesting()
45
45
46
46
}
47
47
48
- public class MyStack < T >
48
+ public class MyStack < T > where T : IEquatable < T >
49
49
{
50
50
private readonly Queue < T > q1_above ;
51
51
private readonly Queue < T > q2_below ;
@@ -61,11 +61,38 @@ public MyStack()
61
61
debug_stack = new Stack < T > ( ) ;
62
62
}
63
63
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
+
64
92
public string Debug_View
65
93
{
66
94
get
67
95
{
68
-
69
96
// Using screen coordinates convention for
70
97
// the visualization: 0,0 is at upper left
71
98
You can’t perform that action at this time.
0 commit comments