• + 0 comments

    I keep getting this error and I dont know how to reslove PLease help!! avl.java:319: error: cannot find symbol root=root.insert(root,nv); ^ symbol: method insert(Node,int) location: variable root of type Node 1 error class Solution {

     int Max(int a, int b)
    {
        if(a>b)
        {
            return a;
        }
        else 
        {
            return b;
        }
    }
    
      Node leftrot(Node x)
    {
        Node y = x.right;
        Node t2 = y.left;
    
        y.left = x;
        x.right = t2;
    
        x.ht = Max(height(x.left),height(x.right)+1);
        y.ht = Max(height(x.left),height(x.right)+1);
    
        return y;
    }
      Node rightrot(Node x)
    {
        Node y = x.left;
        Node t2 = y.right;
    
        y.right = x;
        x.left = t2;
    
        x.ht = Max(height(x.left),height(x.right))+1;
        y.ht = Max(height(x.left),height(x.right))+1;
    
        return y;
    
    }
     int height(Node n)
    {
        if(n == null)
        {
            return 0;
        }
        return n.ht;
    }
     int getBalance(Node node)
    {
        if(node == null)
        {
            return 0;
        }
        return height(node.left) - height(node.right);
    }
    
     Node insert(Node root,int data)
    {
        if(root==null)
        {
             Node node = new Node();
            node.val = val;
            node.ht = 0;
            node.left = null;
            node.right = null;
            return node;
        }
        if(root.val < data)
        {
            root.right = insert(root.right, data);
        }
        else if(root.val > data)
        {
            root.left = insert(root.left, data);
        }
        else
        {
            return root;
        }
        root.ht = Max(height(root.left), height(root.right))+1;
    
        int balance = getBalance(root);
    
        if(balance > 1 && data < root.left.val)
        {
            return rightrot(root);
        }
        if(balance < -1 && data > root.right.val)
        {
            return leftrot(root);
        }
        if(balance > 1 && data > root.left.val)
        {
            root.left = leftrot(root.left);
            return rightrot(root);
        }
        if(balance < -1 && data < root.right.val)
        {
            root.right = rightrot(root.right);
            return leftrot(root);
        }
        return root;
    }
    
        avl.java:319: error: cannot find symbol
        root=root.insert(root,nv);
                 ^