| 264 | |
| 265 | |
| 266 | def 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. |