File tree 1 file changed +4
-7
lines changed
1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change 6
6
7
7
8
8
class TreeNode :
9
-
10
9
def __init__ (self , data ):
11
10
self .data = data
12
11
self .right = None
@@ -49,26 +48,23 @@ def pre_order(node):
49
48
50
49
51
50
def 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 :
54
52
return
55
53
in_order (node .left )
56
54
print (node .data , end = " " )
57
55
in_order (node .right )
58
56
59
57
60
58
def 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 :
63
60
return
64
61
post_order (node .left )
65
62
post_order (node .right )
66
63
print (node .data , end = " " )
67
64
68
65
69
66
def 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 :
72
68
return
73
69
q = queue .Queue ()
74
70
q .put (node )
@@ -83,6 +79,7 @@ def level_order(node):
83
79
84
80
if __name__ == '__main__' :
85
81
import sys
82
+
86
83
print ("\n ********* Binary Tree Traversals ************\n " )
87
84
# For python 2.x and 3.x compatibility: 3.x has not raw_input builtin
88
85
# otherwise 2.x's input builtin function is too "smart"
You can’t perform that action at this time.
0 commit comments