我的代码是:
class Tree
attr_accessor :node, :left, :right
def initialize(*args)
self.node = args[0]
self.left = args[1]
self.right = args[2]
end
def inorder
if self.left
self.left.inorder
else
return
end
puts self.node
if self.right
self.right.inorder
else
return
end
end
end
t2 = Tree.new 2
t1 = Tree.new 1
t = Tree.new 3,t1,t2
t.inorder
仅打印根节点 3。这里出了什么问题?