class Algorithmable::DataStructs::Stack

Public Class Methods

new(collection = []) click to toggle source
# File lib/algorithmable/data_structs/stack.rb, line 9
def initialize(collection = [])
  @imp = Deque.new
  collection.each { |item| @imp.push_front item }
end

Public Instance Methods

peek() click to toggle source
# File lib/algorithmable/data_structs/stack.rb, line 14
def peek
  peek_value = @imp.peek_front
  fail NoSuchElementError unless peek_value
  peek_value
end
pop() click to toggle source
# File lib/algorithmable/data_structs/stack.rb, line 24
def pop
  @imp.pop_front
end
push(item) click to toggle source
# File lib/algorithmable/data_structs/stack.rb, line 20
def push(item)
  @imp.push_front(item)
end
to_s() click to toggle source
# File lib/algorithmable/data_structs/stack.rb, line 28
def to_s
  to_a.join '->'
end