fork download
  1. class Node
  2. attr_accessor :rootNode, :leftNode, :rightNode, :treeItem
  3.  
  4. def initialize(treeItem, root)
  5. @treeItem = treeItem
  6. @rootNode = root
  7. @leftNode = nil
  8. @rightNode = nil
  9. end
  10.  
  11. def insertToTree(newItem)
  12. if @rootNode == nil
  13. @rootNode = Node.new(newItem, newItem.top)
  14. elsif @rootNode.treeItem.compareTo(newItem) < 0 #calls the member function
  15. @leftNode.insertToTree(newItem)
  16. else
  17. @rightNode.insertToTree(newItem)
  18. end
  19. end
  20.  
  21. end
  22.  
  23. class TreeItem
  24. include TreeStuff
  25. def compareTo(newItem)
  26. self.data <=> newItem.data
  27. end
  28. end #TreeItem
Runtime error #stdin #stdout #stderr 0.02s 7456KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.rb:24:in `<class:TreeItem>': uninitialized constant TreeItem::TreeStuff (NameError)
	from prog.rb:23:in `<main>'