0

I have made an ArrayList that has been filled with values from a unbalanced binary tree (the objects in the ArrayList are InOrder traversal sorted).

When I go to build the binary tree in my LinkedBinaryTree class I get a "cannot find symbol error" from the compiler. I am so stumped, here is what I've tried.

1) I successfully placed values (not from an arrayList) into the binary tree just to see if I understood the general framework correctly (Tree's are comprised of nodes) and used a print line function to print the root, then print the left side root etc etc. This worked.

2) I then tried to build a method that takes an already InOrder sorted ArrayList as a parameter, and uses subList to recursively build the left and right tree's. I get the "cannot find symbol" error, and went through this stickied post

What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?

to try and figure out which issue is causing the problem. I am absolutely stumped.

public LinkedBinaryTree BinaryBalanceTreeMethod(java.util.List delta) {
    if (delta.isEmpty()) {
        return null;
    }

    int middle = delta.size() / 2;
    LinkedBinaryTree tree = new LinkedBinaryTree(delta.get(middle));
    tree.getRootNode.setLeft(BinaryBalanceTreeMethod(delta.subList(0, middle)));
    tree.getRootNode.setRight(BinaryBalanceTreeMethod((delta.subList(middle + 1, delta.size()))));
    return tree;    
}

In case anyone needs to see the main method...

Iterator it = treez.iteratorInOrder();
java.util.List listz = new java.util.ArrayList();

while (it.hasNext()) {
    listz.add(it.next());
}
System.out.println(listz.toString());
LinkedBinaryTree test = new LinkedBinaryTree()
test.BinaryBalanceTreeMethod(listz);

System.out.println(test.getRootElement());

I should note - I have another class called ArrayList so I have to use that java.util.ArrayList to instantiate.

1 Answers1

1

In your main method you missed semicolon ; in the end of LinkedBinaryTree test = new LinkedBinaryTree()

System.out.println(listz.toString());
LinkedBinaryTree test = new LinkedBinaryTree() // you missed the ; here
test.BinaryBalanceTreeMethod(listz);
E. Shcherbo
  • 1,128
  • 8
  • 15