munmunbb
munmunbb

Reputation: 417

Unable to get left/right in TreeNode class

I was working on a problem regarding to binary search tree using java. The name of the built-in class in TreeNode. In the solution, it shows

enter image description here

However, when I did the implementation myself, I am not able to do "root.left" or "root.right". I was wondering if I missed anything? Thanks!

Upvotes: 0

Views: 2875

Answers (1)

James S
James S

Reputation: 308

Accessing right/left in that way would imply a TreeNode that is implemented in this way:

public class TreeNode<T> {
    public TreeNode<T> right;
    public TreeNode<T> left;
    public T value;
}

Upvotes: 2

Related Questions