class RubyCollections::Stack
Public Class Methods
new(arr = [])
click to toggle source
TODO: implement iterator TODO: implement to_a
# File lib/ruby_collections/stack.rb, line 7 def initialize(arr = []) @arr = arr end
Public Instance Methods
isEmpty?()
click to toggle source
# File lib/ruby_collections/stack.rb, line 15 def isEmpty? @arr.size.zero? end
pop()
click to toggle source
# File lib/ruby_collections/stack.rb, line 27 def pop @arr.shift end
push(e)
click to toggle source
# File lib/ruby_collections/stack.rb, line 23 def push(e) @arr.unshift(e) end
size()
click to toggle source
# File lib/ruby_collections/stack.rb, line 11 def size @arr.size end
top()
click to toggle source
# File lib/ruby_collections/stack.rb, line 19 def top @arr[0] end