def list2Tree_n(L): if len(L) == 0: return None m = len(L) // 2 return bst.BSTNode(L[m], left=list2Tree_n(L[:m]), right=list2Tree_n(L[m + 1:]))
def list2Tree_n(L): if L == None or len(L) == 0: return None mid = len(L) // 2 node = bst.BSTNode(L[mid]) node.left = list2Tree_n(L[:mid]) node.right = list2Tree_n(L[mid+1:]) return node
def list2Tree(L): if len(L) == 0: # when list is empty return none return None # find mid of list midpoint = len(L) // 2 # set root as a node containing the data of midpoint then create recursive call # for left half and then right half, then return the root root = bst.BSTNode(L[midpoint]) root.left = list2Tree(L[:midpoint]) root.right = list2Tree(L[midpoint + 1:]) return root
def setUp(self): self.myT = bst.BSTree(bst.BSTNode(1,None,None)) self.myT.insert(9)
def make_bst_n(T): t = bst.BSTNode(T.data[0]) if not T.is_leaf: t.left = make_bst_n(T.child[0]) t.right = make_bst_n(T.child[1]) return t