MCPcopy Create free account
hub / github.com/geekcomputers/Python / postorder_itr

Function postorder_itr

binary_search_tree.py:248–263  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

246
247
248def postorder_itr(node):
249 # L R N
250 # 1. Push root to first stack.
251 # 2. Loop while first stack is not empty
252 # 2.1 Pop a node from first stack and push it to second stack
253 # 2.2 Push left and right children of the popped node to first stack
254 # 3. Print contents of second stack
255 s1, s2 = [node], []
256 while s1 != []:
257 temp = s1.pop()
258 s2.append(temp)
259 if temp.left:
260 s1.append(temp.left)
261 if temp.right:
262 s1.append(temp.right)
263 print(*(s2[::-1]))
264
265
266def bst_frm_pre(pre_list):

Callers

nothing calls this directly

Calls 2

popMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected