Skip to content

Commit 4140522

Browse files
rajansh87cclauss
andauthored
Update data_structures/binary_tree/binary_tree_traversals.py
Co-authored-by: Christian Clauss <[email protected]>
1 parent 2c9050c commit 4140522

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

data_structures/binary_tree/binary_tree_traversals.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,21 @@ def __init__(self, data):
99
self.data = data
1010

1111

12+
def make_tree() -> Node:
13+
root = Node(1)
14+
root.left = Node(2)
15+
root.right = Node(3)
16+
root.left.left = Node(4)
17+
root.left.right = Node(5)
18+
return root
19+
20+
1221
def preorder(root):
1322
"""
1423
PreOrder traversal: visit root node then its left subtree followed by right subtree.
24+
25+
>>> preorder(make_tree())
26+
4 2 5 1 3
1527
"""
1628
if root:
1729
print(root.data, end=" ")

0 commit comments

Comments
 (0)