Rooted Binary Tree - Chain Nodes Algorithm
The number of chain nodes of a rooted binary tree with two non-empty sons is the sum of the chain nodes in its sons.

Also, the number of chain nodes of a rooted binary tree with only one non-empty son is the number of chain nodes of the son plus one.

If a rooted binary tree has no non-empty sons, its number of chain nodes is zero.

And finally, the number of chain nodes of an empty rooted binary tree is zero.

So, following this properties we have

int chainNodes(tree T) {
    if (T is empty)
        return 0;
    if (T has no nonempty sons)
        return 0;
    if (T has only one nonempty son)
        return chainNodes(son)+1;
    if (T has two nonempty sons)
        return chainNoodes(leftSon)+chainNodes(rightSon);
}


which is similar to your try.