Skip to content

Commit b5285c1

Browse files
authored
Update binary_tree_traversals.py
1 parent f15601c commit b5285c1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

data_structures/binary_tree/binary_tree_traversals.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ def height(root):
4040
"""
4141
if not root:
4242
return 0
43-
leftHeight=height(root.left)
44-
rightHeight=height(root.right)
45-
if leftHeight>rightHeight:
46-
return leftHeight+1
43+
left_Height=height(root.left)
44+
right_Height=height(root.right)
45+
if left_Height>right_Height:
46+
return left_Height+1
4747
else:
48-
return rightHeight+1
48+
return right_Height+1
4949

5050
def levelorder1(root):
5151
"""
@@ -77,7 +77,7 @@ def levelorder2(root,level):
7777
levelorder2(root.left,level-1)
7878
levelorder2(root.right,level-1)
7979

80-
def printlefttoright(root,level):
80+
def print_left_to_right(root,level):
8181
"""
8282
Print elements on particular level from left to right direction of the binary tree.
8383
"""
@@ -86,10 +86,10 @@ def printlefttoright(root,level):
8686
if level==1:
8787
print(root.data,end=" ")
8888
elif level>1:
89-
printlefttoright(root.left,level-1)
90-
printlefttoright(root.right,level-1)
89+
print_left_to_right(root.left,level-1)
90+
print_left_to_right(root.right,level-1)
9191

92-
def printrighttoleft(root,level):
92+
def print_right_to_left(root,level):
9393
"""
9494
Print elements on particular level from right to left direction of the binary tree.
9595
"""
@@ -98,8 +98,8 @@ def printrighttoleft(root,level):
9898
if level==1:
9999
print(root.data,end=" ")
100100
elif level>1:
101-
printrighttoleft(root.right,level-1)
102-
printrighttoleft(root.left,level-1)
101+
print_right_to_left(root.right,level-1)
102+
print_right_to_left(root.left,level-1)
103103

104104
def zigzag(root):
105105
"""
@@ -109,10 +109,10 @@ def zigzag(root):
109109
height_tree=height(root)
110110
for h in range(1,height_tree+1):
111111
if flag==0:
112-
printlefttoright(root,h)
112+
print_left_to_right(root,h)
113113
flag=1
114114
else:
115-
printrighttoleft(root,h)
115+
print_right_to_left(root,h)
116116
flag=0
117117

118118
def main(): # Main function for testing.

0 commit comments

Comments
 (0)