def list_to_tree(l): if not l: return None mid = (len(l)-1)/2 n = Node(l[mid]) n.left = list_to_tree(l[:mid]) n.right = list_to_tree(l[(mid+1):]) return n
def recurse(l,left,right): if left > right: return None mid = (left+right)/2 n = Node(l[mid]) n.left = recurse(l,left,mid-1) n.right = recurse(l,mid+1,right) return n
def list_to_tree_parent(l): if not l: return None mid = (len(l)-1)/2 n = Node(l[mid]) n.parent = None n.left = list_to_tree_parent(l[:mid]) if n.left: n.left.parent = n n.right = list_to_tree_parent(l[(mid+1):]) if n.right: n.right.parent = n return n