|
|
|
@ -4,6 +4,15 @@ class BSTNode: |
|
|
|
self.left = None |
|
|
|
self.right = None |
|
|
|
|
|
|
|
def height(self): |
|
|
|
lh = 0 |
|
|
|
rh = 0 |
|
|
|
if self.left is not None: |
|
|
|
lh = self.left.height() |
|
|
|
if self.right is not None: |
|
|
|
rh = self.right.height() |
|
|
|
return 1 + max(lh, rh) |
|
|
|
|
|
|
|
|
|
|
|
class BST: |
|
|
|
def __init__(self): |
|
|
|
@ -49,7 +58,7 @@ class BST: |
|
|
|
return tree |
|
|
|
|
|
|
|
def height(self): |
|
|
|
return rec_height(self.root) |
|
|
|
return self.root.height() |
|
|
|
|
|
|
|
|
|
|
|
def inOrderRec(top, ret): |
|
|
|
@ -62,12 +71,6 @@ def inOrderRec(top, ret): |
|
|
|
inOrderRec(top.right, ret) |
|
|
|
|
|
|
|
|
|
|
|
def rec_height(node: BSTNode): |
|
|
|
if node is None: |
|
|
|
return 0 |
|
|
|
return 1 + max(map(rec_height, (node.left, node.right))) |
|
|
|
|
|
|
|
|
|
|
|
def add_rec(start, end, list_param, tree: BST): |
|
|
|
if end - start >= 0: |
|
|
|
mid = (start + end) // 2 |
|
|
|
|