Hi guys, I've searched this, but can't find a solution. Basically what I'm doing is writing a binary search tree (which works) and balancing it with AVL (which almost works). As far as I can tell my AVL tree is implemented correctly, but I'm getting a stack overflow error at this part:
private int GetHeight(Node<T> node)
{
if (node!=null)
{
return (1+Math.Max(GetHeight(node.LeftChild), GetHeight(node.RightChild)));
}
else return 0;
}
I'm using this to get the height of the tree, which I later use to calculate the tree's balance factor. I develop on Linux, but I tested this code in Windows just to be sure it wasn't an issue with MonoDevelop.
I'm retrieving this value in a method by doing
return (GetHeight(node.RightChild) - GetHeight(node.LeftChild));
Any idea what's causing this problem?