diff --git a/01_binary_search_trees/bst.py b/01_binary_search_trees/bst.py index 561ca41..163475b 100644 --- a/01_binary_search_trees/bst.py +++ b/01_binary_search_trees/bst.py @@ -134,4 +134,13 @@ class BinarySearchNode(): """ prints a single tree node. """ - return (str(self.left_child.value) + " " + str(self.value) + " " + str(self.right_child.value) ) \ No newline at end of file + ret = "" + if self.has_left_child(): + ret += str(self.left_child.value) + " " + + ret += str(self.value) + + if self.has_right_child(): + ret += " " + str(self.right_child.value) + + return ret \ No newline at end of file diff --git a/01_binary_search_trees/bst_test.py b/01_binary_search_trees/bst_test.py index badf96b..187a814 100644 --- a/01_binary_search_trees/bst_test.py +++ b/01_binary_search_trees/bst_test.py @@ -208,5 +208,9 @@ class test_binary_search_tree(unittest.TestCase): self.assertEqual(bst.__str__(), "4 6 10") + self.assertEqual(bst.root_node.right_child.__str__(), "10 16") + self.assertEqual(bst.root_node.right_child.right_child.__str__(), "16") + + if __name__ == '__main__': unittest.main()