[CODE=Java]static Node root;
static int countNode;
...
public BSTree() {
root = null;
}
...
public int size () {
return countNode;
}
[/CODE]
I just noticed that the root and the countNode (tree size) fields are static. What happens when you have another tree?
Originally posted by JosAH
Those variables are static because trees themselves don't move either; when will
people ever learn ...
kind regards,
Jos ;-)
Thanks Jos for defending the objective. In this problem we were not assigned to make multiple BSTrees, rather just one tree which would have all these functions. :)
As far as writing a non-recursive (loop-iterative) height function is concerned, I could not come up with any and therefore implemented an overridden recursive function in the same class and called that recursive function from this non-recursive function.
I know that wasn't what I was supposed to do but I didnt have any bright ideas until the very last minute of my submission. Time for a compromise..eh
Thanks Jos for defending the objective. In this problem we were not assigned to make multiple BSTrees, rather just one tree which would have all these functions. :)
I would rethink that, if I were you. You are going out of your way to make your code less general. If you insist on having static data, then all the methods should be made static, and the constructor hidden, because you've given up on a class that is designed to be instantiated.
Comment