I have built a splay tree and I am trying to print it out reverse in order so that when you turn your head to the left you can see the tree in a normal manner. I have written the following code and it outputs the tree somewhat correctly but it adds extra spaces in on the rightmost node and it doesn't add spaces for all of the child nodes that should be placed below the root node:
public void printReverseInOrder() {
if (root != null) {
reverseInOrder(root, 0);
}
else {
System.out.println();
}
}
public void reverseInOrder(BSTnode h, int indent) {
if (h != null) {
for (int i = 0; i < indent; i++) {
System.out.print(" ");
}
indent++;
reverseInOrder(h.right, indent);
reverseInOrder(h.left, indent);
System.out.println(h.data);
indent--;
}
}
I feel like it may be an error with either my recursion or the placement of my indent additions and subtractions.