Closed brendacano closed 3 years ago
What I did was print the value of the key using node.getKey();
This won't work for anything other than Integers or Strings I don't think, but I believe the test case is written with ints.
I thinnk you can do something like this
I thinnk you can do something like this
Thats what I did but it prints out as:
I thinnk you can do something like this
Thats what I did but it prints out as:
hmm thats weird mine shows something like this
^Yeah, you should use .getKey(). If you print the tree itself all you will get are the memory addresses of the nodes.
Kristi, did you write a .toString() method?
^Yeah, you should use .getKey(). If you print the tree itself all you will get are the memory addresses of the pointers.
Kristi, did you write a .toString() method?
no i just imported the classes that Dr. Choi had in his test
^ yeah i did the same thing, weird how it doesn't work for everyone
Oh, that IS strange.
Okay, I figured it out. In AbstractBinaryNode.java there is supposed to be this function: @Override public String toString() { return key + " -> (" + left_child + ", " + right_child + ")"; } I just looked through the codes and checked if there was a discrepancy between the code I had written code with the code in the repository. I added the function and now it actually prints.
Thanks for the help guys, it helped me find the root of the issue.
When I try to print the tree using the toString function, it doesn't give me the numbers and instead gives me variations of BinaryNode@452459b3. How do I address this so I can check if my method actually works as well as to visualize AVLTree and RedBlackTree?