def main(): t = TreeInitializer() tree = Tree() arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] tree = t.arr_to_tree(arr, 0, 9) print tree.in_order_traversal() print t.array
def arr_to_tree(self, arr, start, end): # create a tree object # ensure that the array is empty before appending to it if self.array != []: self.array = [] t = Tree() # create the node structure from the array structure = self._ordered_array_to_node(arr, start, end) # populate the global list according to the node structure self._pre_order_traversal(structure) # populate the tree using the global array for i in xrange(len(self.array)): t.add(self.array[i]) # return the tree return t