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

Function vertical_middle_level

binary_search_tree.py:306–319  ·  view source on GitHub ↗
(t_node)

Source from the content-addressed store, hash-verified

304
305# Function to print element vertically which lie just below the root node
306def vertical_middle_level(t_node):
307 e = (t_node, 0) # 0 indicates level 0, to left we have -ve and to right +ve
308 queue = [e]
309 ans = []
310 # Do a level-order traversal and assign level-value to each node
311 while queue != []:
312 temp, level = queue.pop(0)
313 if level == 0:
314 ans.append(str(temp.info))
315 if temp.left:
316 queue.append((temp.left, level - 1))
317 if temp.right:
318 queue.append((temp.right, level + 1))
319 return " ".join(ans)
320
321
322def get_level(n, val):

Callers

nothing calls this directly

Calls 2

popMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected