So I have this:
Code:
template <typename K, typename V>
void Map<K,V>::print() {
if (!this) {
cout << "THIS PROGRAM SUCKS" << endl;
return;
}
cout << key << " " << value << endl;
left->print();
right->print();
}
And for some reason, I'm printing out the key and value twice when I have a single element. I seriously don't understand why; my logic is that since left and right are both null, the recursive calls to them should return automatically. Also, "THIS PROGRAM SUCKS" is printing out three times as well.
What's wrong with my recursion?
EDIT: Owait, I'm stupid. I forgot 1 return statement, which allowed 2 cases to happen at once, creating a node, and then creating an identical node to the right.
Bookmarks