enhances print node to take care of more special cases

This commit is contained in:
2013-07-12 21:21:20 +02:00
parent cf753f8ac4
commit e731857f82
2 changed files with 14 additions and 1 deletions

View File

@@ -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) )
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

View File

@@ -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()