Commit 8b56ea9

mo khan <mo.khan@gmail.com>
2020-08-22 21:35:19
Quick and dirty implementation
1 parent 64b0dd1
Changed files (1)
2020
08
2020/08/22/main.rb
@@ -0,0 +1,35 @@
+def assert_equal(x, y)
+  raise [x, y].inspect unless x == y
+end
+
+class MaxStack
+  def initialize
+    @items = []
+  end
+
+  def push(value)
+    @items.push(value)
+  end
+
+  def pop
+    @items.pop
+  end
+
+  def max
+    @items.max
+  end
+end
+
+stack = MaxStack.new
+stack.push(1)
+stack.push(2)
+stack.push(3)
+stack.push(2)
+
+assert_equal 3, stack.max
+
+stack.pop
+stack.pop
+assert_equal 2, stack.max
+
+puts 'Yay!'