Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I do not know the solution of this, a program of an AVLTREEHow can i solve the error error: cannot find symbol node = rotateWithRightChild(node);

This is the code of my program, it is an AVL Tree but it shows error error: cannot find symbol
This error message is indicating that the compiler cannot find the symbol rotateWithRightChild. This typically happens when a method or variable is not defined in the current scope.

import java.util.Scanner;

class Node
{
    int element;
    int h;
    Node leftChild;
    Node rightChild;
    
    public Node()
    {
        leftChild = null;
        rightChild = null;
        element = 0;
        h = 0;
    }
    
    public Node(int element)
    {
        leftChild = null;
        rightChild = null;
        this.element = element;
        h = 0;
    }
}

class ConstructAVLTree
{ 
   private Node rootNode;
   
   public ConstructAVLTree()
   {
    rootNode = null;
   }
   
   public void removeAll()
   {
     rootNode = null;
   }
   
   public boolean checkEmpty()
   {
     if(rootNode == null)
        return true;
        else
            return false;
   }
   
   public void insertElement(int element)
   {
    rootNode = insertElement (element, rootNode);
   }
   
   private int getHeight(Node node)
   {
    return node == null ?-1 : node.h;
   }
   
   private int getMaxHeight(int leftNodeHeight, int rightNodeHeight)
   {
    return leftNodeHeight > rightNodeHeight ? leftNodeHeight : rightNodeHeight;
   }
   
   private Node insertElement(int element, Node node)
   {
    if (node== null)
        node = new Node(element);
            else if (element < node.element)
            {
                node.leftChild = insertElement( element, node.leftChild);
                if (getHeight(node.leftChild)- getHeight(node.rightChild) == 2)
                    if (element < node.leftChild.element)
                        node = rotateWithLeftChild(node);
                        else
                            node = doubleWithLeftChild(node);
            }
            else if ( element > node.element)
            {
                node.rightChild = insertElement( element, node.rightChild);
                if (getHeight(node.rightChild)- getHeight(node.leftChild) == 2)
                    if (element > node.rightChild.element)
                        node = rotateWithRightChild(node);
                        else
                            node = doubleWithRightChild(node);
                
            }
            else
                node.h = getMaxHeight(getHeight(node.leftChild), getHeight(node.rightChild))+1;
                
                return node;
   }
   
   private Node rotateWithLeftChild(Node node2)
   {
      Node node1 = node2.leftChild;
      node2.leftChild = node1.rightChild;
      node1.rightChild = node2;
      node2.h = getMaxHeight( getHeight(node2.leftChild), getHeight(node2.rightChild)) + 1;
      node1.h = getMaxHeight( getHeight(node1.leftChild), node2.h) + 1;
      return node1;
   }
   private Node doubleWithLeftChild(Node node3)
   {
   
    node3.leftChild = rotateWithRightChild( node3.leftChild);
    return rotateWithLeftChild (node3);
   }
   
   private Node doubleWithRightChild( Node node1)
   {
    node1.rightChild = rotateWithLeftChild( node1.rightChild);
    return rotateWithRightChild(node1);
   }
   
   public int getTotalNumberOfNodes()
   {
     return getTotalNumberOfNodes(rootNode);
   }
   private int getTotalNumberOfNodes(Node head)
   {
    if (head==null)
        return 0;
        else
        {
            int length = 1;
            length = length + getTotalNumberOfNodes(head.leftChild);
            length = length + getTotalNumberOfNodes(head.rightChild);
            return length;
        }
   }
   public boolean searchElement(int element)
   {
    return searchElement(rootNode, element);
   }
   
   private boolean searchElement(Node head, int element)
   {
    boolean check = false;
    while ((head != null) && !check)
    {
        int headElement = head.element;
        if ( element < headElement)
            head = head.leftChild;
            else if (element > headElement)
                head = head.rightChild;
                else
                {
                    check = true;
                    break;
                }
                check = searchElement(head, element);
    }
    return check;
    }
    
    public void inorderTraversal()
    {
        inorderTraversal(rootNode);
    }
    private void inorderTraversal(Node head)
    {
        if (head != null);
        {
            inorderTraversal(head.leftChild);
                System.out.print(head.element+ "");
                inorderTraversal(head.rightChild);
        }
    }
    
    public void preorderTraversal()
    {
        preorderTraversal(rootNode);
    }
    private void preorderTraversal(Node head)
    {
        if (head != null)
        {
            System.out.print(head.element + "");
                preorderTraversal(head.leftChild);
                preorderTraversal(head.rightChild);
        }
    }
    
    public void postorderTraversal()
    {
        postorderTraversal(rootNode);
    }
    
    private void postorderTraversal(Node head)
    {
        if (head!= null)
    
        {
            postorderTraversal(head.leftChild);
            postorderTraversal(head.rightChild);
            System.out.print(head.element+ "");
        }
    }
    
    
   }

    

      error: cannot find symbol "node = rotateWithRightChild(node);"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

your code defines only method rotateWithLeftChild. Please add method rotateWithRightChild.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading