Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int tree :: elem_with_one_child(tree_node *root)
- {
- int count=0;
- if(!root)
- return 0;
- if(!root->left && !root->right)
- return 0;
- if((root->left == 0 && root->right) || (root->left && root->right == 0))
- {
- if(root->left)
- count+=elem_with_one_child(root->left);
- if(root->right)
- count+=elem_with_one_child(root->right);
- count++;
- }
- else
- {
- count+=elem_with_one_child(root->right);
- count+=elem_with_one_child(root->left);
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement