File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 11"""
22This is pure python implementation of tree traversal algorithms
33"""
4-
4+ from __future__ import print_function
55import queue
66
77
@@ -25,22 +25,25 @@ def build_tree():
2525 node_found = q .get ()
2626 print ("Enter the left node of %s: " % node_found .data , end = "" )
2727 left_data = eval (input ())
28- if left_data >= 0 :
28+ if left_data < 0 :
29+ return tree_node
30+ elif left_data >= 0 :
2931 left_node = TreeNode (left_data )
3032 node_found .left = left_node
3133 q .put (left_node )
3234 print ("Enter the right node of %s: " % node_found .data , end = "" )
3335 right_data = eval (input ())
34- if right_data >= 0 :
36+ if right_data < 0 :
37+ return tree_node
38+ elif right_data >= 0 :
3539 right_node = TreeNode (right_data )
3640 node_found .right = right_node
3741 q .put (right_node )
38- return tree_node
3942
4043
4144def pre_order (node ):
4245 if not isinstance (node , TreeNode ) or not node :
43- print ("Invalid input" )
46+ # print("Invalid input")
4447 return
4548 print (node .data , end = " " )
4649 pre_order (node .left )
You can’t perform that action at this time.
0 commit comments