template <typename T>
int ct2 (tnode<T> *t)
{
int ctLeft, ctRight, ct;
if (t == NULL)
return 0;
else {
return ct2(t->left)+ct2(t->right)+
((t->left != NULL && t->right != NULL) ? 1 : 0);
}
I tried running it and I still can't figure out what it does. Specifically the return part in function ct2.
This is tnode.h :
#ifndef TREENODE
#define TREENODE
// represents a node in a binary tree
template <typename T>
class tnode
{
public:
T nodeValue;
tnode<T> *left, *right;
// default constructor. data not initialized
tnode()
{}
tnode (const T& item, tnode<T> *lptr = NULL,
tnode<T> *rptr = NULL):
nodeValue(item), left(lptr), right(rptr)
{}
};
#endif