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

Function inorder_itr

binary_search_tree.py:224–245  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

222
223
224def inorder_itr(node):
225 # L N R : Left, Node, Right
226 # 1) Create an empty stack S.
227 # 2) Initialize current node as root
228 # 3) Push the current node to S and set current = current->left until current is NULL
229 # 4) If current is NULL and stack is not empty then
230 # a) Pop the top item from stack.
231 # b) Print the popped item, set current = popped_item->right
232 # c) Go to step 3.
233 # 5) If current is NULL and stack is empty then we are done.
234 stack = []
235 current = node
236 while True:
237 if current != None:
238 stack.append(current) # L
239 current = current.left
240 elif stack != []:
241 temp = stack.pop()
242 print(temp.info) # N
243 current = temp.right # R
244 else:
245 break
246
247
248def postorder_itr(node):

Callers

nothing calls this directly

Calls 2

appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected