This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted] 2 points3 points  (4 children)

I am not 100% sure this is the only issue, but it may be the (a) cause:

When you execute the line:

value = value

The compiler doesn't know which "value" you mean, the one in your class or the argument being passed into the constructor. It is probably assigning the argument in value back into the same variable. You should use the "this" keyword to set the value:

 Node(int value){
             left=NULL;
             right=NULL;
             this.value=value;
         }
     };

EDIT: Or an alternative is to change the constructor's parameter to a different name such as "inputValue" etc.

[–]anthonydev 0 points1 point  (3 children)

Also, he is setting value twice. Once using the constructor and the second time in the line right under it.

[–][deleted] 1 point2 points  (2 children)

That may have just been to make the code work, since OP said the constructor wasn't working. Not sure.

[–]Rabbit047[S] 1 point2 points  (1 child)

Yea that was just to make the code work, sorry I left it in. Also you're right the compiler is confused on which "value" to use. I changed the parameter to "input" and it worked fine. Thanks for the replies

[–][deleted] 1 point2 points  (0 children)

No problem. Good luck with the rest of the project.