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

Function bst_frm_pre

binary_search_tree.py:266–285  ·  view source on GitHub ↗
(pre_list)

Source from the content-addressed store, hash-verified

264
265
266def bst_frm_pre(pre_list):
267 box = Node(pre_list[0])
268 if len(pre_list) > 1:
269 if len(pre_list) == 2:
270 if pre_list[1] > pre_list[0]:
271 box.right = Node(pre_list[1])
272 else:
273 box.left = Node(pre_list[1])
274 else:
275 all_less = False
276 for i in range(1, len(pre_list)):
277 if pre_list[i] > pre_list[0]:
278 break
279 else:
280 all_less = True
281 if i != 1:
282 box.left = bst_frm_pre(pre_list[1:i])
283 if not all_less:
284 box.right = bst_frm_pre(pre_list[i:])
285 return box
286
287
288# Function to find the lowest common ancestor of nodes with values c1 and c2.

Callers

nothing calls this directly

Calls 1

NodeClass · 0.70

Tested by

no test coverage detected