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

Function post_order_iter

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

Source from the content-addressed store, hash-verified

137
138
139def post_order_iter(node):
140 if not isinstance(node, TreeNode) or not node:
141 return
142 stack1, stack2 = [], []
143 n = node
144 stack1.append(n)
145 while stack1: # to find the reversed order of post order, store it in stack2
146 n = stack1.pop()
147 if n.left:
148 stack1.append(n.left)
149 if n.right:
150 stack1.append(n.right)
151 stack2.append(n)
152 while stack2: # pop up from stack2 will be the post order
153 print(stack2.pop().data, end=" ")
154
155
156if __name__ == '__main__':

Callers 1

Calls 1

popMethod · 0.45

Tested by

no test coverage detected