Skip to content

Commit 1605604

Browse files
committed
Added a python file to Implement Preorder, Inorder, and Postorder traversals in one traversal.
1 parent 980930e commit 1605604

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

data_structures/binary_tree/all_traversals_one_pass.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Node:
1919
The left child of the node.
2020
right : Node, optional
2121
The right child of the node.
22+
23+
Reference: https://en.wikipedia.org/wiki/Binary_tree
2224
"""
2325

2426
def __init__(self, data: int):
@@ -66,6 +68,10 @@ def all_traversals(root: Optional[Node]) -> Tuple[List[int], List[int], List[int
6668
- If state == 3:
6769
→ Add node to Postorder
6870
3. Continue until stack is empty.
71+
72+
Reference: Tree Traversals- https://en.wikipedia.org/wiki/Tree_traversal
73+
Stack Data Structure- https://en.wikipedia.org/wiki/Stack_(abstract_data_type)
74+
6975
"""
7076

7177
if root is None:
@@ -116,6 +122,8 @@ def build_sample_tree() -> Node:
116122
-------
117123
Node
118124
The root node of the binary tree.
125+
126+
Reference: https://en.wikipedia.org/wiki/Binary_tree
119127
"""
120128
root = Node(1)
121129
root.left = Node(2)

0 commit comments

Comments
 (0)