So I have a program that reads data/text files, with 1 number on each line and makes a binary search tree from it. When i insert a node, there should be two data variables updated, searchcost and key.. Key being the actual number of the element, and the searchcost is 1+the depth of the node. For data files that have numbers up to a certain amount insert works. But if it has numbers above say..3047 then the insert function gives a stack overflow error. Here is the insert method. Debugging says its coming from
t = new BinaryNode(x,count);
but I have no clue why.
BinaryNode *BinarySearchTree::insert(int x,
BinaryNode *t)
{
static long count;
count++;
if (t == NULL){ t = new BinaryNode(x,count);
count=0;
}
else if (x < t->key){
t->left = insert(x, t->left);
}
else if (x > t->key){
t->right = insert(x, t->right);
}
else
throw DuplicateItem();
return t;
}