mirror of
https://github.com/jlengrand/Coding4Interviews.git
synced 2026-03-10 08:11:24 +00:00
Implement simple print method for single node element
This commit is contained in:
@@ -83,7 +83,7 @@ class BinarySearchTree():
|
|||||||
Prints a nice version of the binary search node
|
Prints a nice version of the binary search node
|
||||||
"""
|
"""
|
||||||
#TODO
|
#TODO
|
||||||
return "aaa"
|
return self.root_node.__str__()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_search_tree(a_tree_root):
|
def is_search_tree(a_tree_root):
|
||||||
@@ -129,3 +129,9 @@ class BinarySearchNode():
|
|||||||
|
|
||||||
def has_right_child(self):
|
def has_right_child(self):
|
||||||
return self.right_child is not None
|
return self.right_child is not None
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""
|
||||||
|
prints a single tree node.
|
||||||
|
"""
|
||||||
|
return (str(self.left_child.value) + " " + str(self.value) + " " + str(self.right_child.value) )
|
||||||
@@ -200,7 +200,13 @@ class test_binary_search_tree(unittest.TestCase):
|
|||||||
node_val4 = 16
|
node_val4 = 16
|
||||||
bst.add(node_val4)
|
bst.add(node_val4)
|
||||||
|
|
||||||
self.assertEqual(bst.__str__(), "aaa")
|
# 6
|
||||||
|
# / \
|
||||||
|
# 4 10
|
||||||
|
# \
|
||||||
|
# 16
|
||||||
|
|
||||||
|
self.assertEqual(bst.__str__(), "4 6 10")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user