class Node
attr_accessor :rootNode, :leftNode, :rightNode, :treeItem
def initialize(treeItem, root)
@treeItem = treeItem
@rootNode = root
@leftNode = nil
@rightNode = nil
end
def insertToTree(newItem)
if @rootNode == nil
@rootNode = Node.new(newItem, newItem.top)
elsif @rootNode.treeItem.compareTo(newItem) < 0 #calls the member function
@leftNode.insertToTree(newItem)
else
@rightNode.insertToTree(newItem)
end
end
end
class TreeItem
include TreeStuff
def compareTo(newItem)
self.data <=> newItem.data
end
end #TreeItem
Y2xhc3MgTm9kZQoJYXR0cl9hY2Nlc3NvciA6cm9vdE5vZGUsIDpsZWZ0Tm9kZSwgOnJpZ2h0Tm9kZSwgOnRyZWVJdGVtCgkKCWRlZiBpbml0aWFsaXplKHRyZWVJdGVtLCByb290KQoJCUB0cmVlSXRlbSA9IHRyZWVJdGVtCgkJQHJvb3ROb2RlID0gcm9vdAoJCUBsZWZ0Tm9kZSA9IG5pbAoJCUByaWdodE5vZGUgPSBuaWwKCWVuZAogIAoJZGVmIGluc2VydFRvVHJlZShuZXdJdGVtKQoJCWlmIEByb290Tm9kZSA9PSBuaWwKCQkJQHJvb3ROb2RlID0gTm9kZS5uZXcobmV3SXRlbSwgbmV3SXRlbS50b3ApCgkJZWxzaWYgQHJvb3ROb2RlLnRyZWVJdGVtLmNvbXBhcmVUbyhuZXdJdGVtKSA8IDAgI2NhbGxzIHRoZSBtZW1iZXIgZnVuY3Rpb24KCQkJQGxlZnROb2RlLmluc2VydFRvVHJlZShuZXdJdGVtKQoJCWVsc2UKCQkJQHJpZ2h0Tm9kZS5pbnNlcnRUb1RyZWUobmV3SXRlbSkKCQllbmQKCWVuZAoJCmVuZAoKY2xhc3MgVHJlZUl0ZW0KICBpbmNsdWRlIFRyZWVTdHVmZgoJZGVmIGNvbXBhcmVUbyhuZXdJdGVtKQoJCXNlbGYuZGF0YSA8PT4gbmV3SXRlbS5kYXRhCgllbmQKZW5kICNUcmVlSXRlbQ==