File tree Expand file tree Collapse file tree 1 file changed +4
-7
lines changed
Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change 66
77
88class TreeNode :
9-
109 def __init__ (self , data ):
1110 self .data = data
1211 self .right = None
@@ -49,26 +48,23 @@ def pre_order(node):
4948
5049
5150def in_order (node ):
52- if not isinstance (node , TreeNode ) or not node :
53- print ("Invalid input" )
51+ if not isinstance (node , TreeNode ) or not node :
5452 return
5553 in_order (node .left )
5654 print (node .data , end = " " )
5755 in_order (node .right )
5856
5957
6058def post_order (node ):
61- if not isinstance (node , TreeNode ) or not node :
62- print ("Invalid input" )
59+ if not isinstance (node , TreeNode ) or not node :
6360 return
6461 post_order (node .left )
6562 post_order (node .right )
6663 print (node .data , end = " " )
6764
6865
6966def level_order (node ):
70- if not isinstance (node , TreeNode ) or not node :
71- print ("Invalid input" )
67+ if not isinstance (node , TreeNode ) or not node :
7268 return
7369 q = queue .Queue ()
7470 q .put (node )
@@ -83,6 +79,7 @@ def level_order(node):
8379
8480if __name__ == '__main__' :
8581 import sys
82+
8683 print ("\n ********* Binary Tree Traversals ************\n " )
8784 # For python 2.x and 3.x compatibility: 3.x has not raw_input builtin
8885 # otherwise 2.x's input builtin function is too "smart"
You can’t perform that action at this time.
0 commit comments