class SpaghettiStack
Constants
- VERSION
Attributes
root[R]
top[R]
Public Class Methods
new(data)
click to toggle source
# File lib/spaghetti_stack.rb, line 23 def initialize(data) @root = Node.new(data) @top = root end
Public Instance Methods
each() { |node| ... }
click to toggle source
# File lib/spaghetti_stack.rb, line 49 def each return self.to_enum unless block_given? node = top until node == root yield node node = node.parent end yield node visited_nodes.each { |visited_node| yield visited_node } self end
inspect()
click to toggle source
Calls superclass method
# File lib/spaghetti_stack.rb, line 64 def inspect output = "" each do |node| data = node.data if node == root output = "(#{data}#{output})" return output else output = " <~ #{data}" + output end end super end
pop()
click to toggle source
# File lib/spaghetti_stack.rb, line 35 def pop node = top parent = node.parent if parent @top = parent visited_nodes << node end end
push(data)
click to toggle source
# File lib/spaghetti_stack.rb, line 28 def push(data) node = Node.new(data, top) @top = node end
Also aliased as: <<
visited_nodes()
click to toggle source
# File lib/spaghetti_stack.rb, line 45 def visited_nodes @visited_nodes ||= [] end