MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / pre_order_iter

Function pre_order_iter

traversals/binary_tree_traversals.py:109–122  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

107
108# iteration version
109def pre_order_iter(node):
110 if not isinstance(node, TreeNode) or not node:
111 return
112 stack = []
113 n = node
114 while n or stack:
115 while n: # start from root node, find its left child
116 print(n.data, end=" ")
117 stack.append(n)
118 n = n.left
119 # end of while means current node doesn't have left child
120 n = stack.pop()
121 # start to traverse its right child
122 n = n.right
123
124
125def in_order_iter(node):

Callers 1

Calls 1

popMethod · 0.45

Tested by

no test coverage detected