Make BST in java using generics from Sorted doubly linked list in parameters.


  • 0
    I
    // Constructor that builds a tree from the values in sorted List L.
    // Initialize variables – root is null and size is 0 - and call 
    // recursive method buildTree() if L.size() > 0.
    // Throws IllegalArgumentException if L is null or any element in L is null
    public BinarySearchTree(List<T> L) 
    {
     return TreeNode(head, tail, L); 
    }
    
    // Builds a balanced tree from the values in sorted List L.
    // Start and end are the start and end positions of a sub-list of L.
    // Returns the root of the subtree containing the elements in the 
    // sub-list of L.
    // Throws IllegalArgumentException if L or any element in L is null.
    // Called by BinarySearchTree(List<T> L) and balance().
    // This is a recursive method.
    // Target Complexity: O(1)
    protected TreeNode<T> buildTree(int start, int end, List<T> L) 
    {
    }
    

    Can anyone help me with the second constructor, as how should I go ahead to make a BST from this sorted list L.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.