I have a node class and am just trying to narrow down an issue when adding elements to my tree. I think my node class is just not properly creating the node to add in the tree. When I print each node, it is returning memory addresses, I believe. I cannot seem to get it to print anything else. Any help in determining if my node class is faulty would be great.
Example of what my program prints:
([C@f72003d)
([C@56dacb7)
([C@63662529)
([C@4711d9ba)
The TreeNode class:
public class TreeNode {
char[] data;
TreeNode left, right, parent;
// used for printing:
int column;
int row;
int center;
public TreeNode(char[] data) {
this.data = data;
left = right = parent = null;
}
@Override
public String toString() {
return "(" + data + ")";
}
public int return_letter(){
char x = data[0];
int b = Character.getNumericValue(x);
return b;
}
public int findMaxDepth() {
int lmax = 0;
int rmax = 0;
if (left != null) {
lmax = left.findMaxDepth();
}
if (right != null) {
rmax = right.findMaxDepth();
}
return 1 + Math.max(lmax, rmax);
}
}
@Override public String toString() {return "(" + data + ")";}will not print what you want. UseArrays.toString(data)to get a String representation of the content of your array.