Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. int tree :: elem_with_one_child(tree_node *root)
  2. {
  3.     int count=0;
  4.     if(!root)
  5.         return 0;
  6.     if(!root->left && !root->right)
  7.         return 0;
  8.     if((root->left == 0 && root->right) || (root->left && root->right == 0))
  9.     {
  10.         if(root->left)
  11.             count+=elem_with_one_child(root->left);
  12.         if(root->right)
  13.             count+=elem_with_one_child(root->right);
  14.         count++;
  15.     }
  16.     else
  17.     {
  18.         count+=elem_with_one_child(root->right);
  19.         count+=elem_with_one_child(root->left);
  20.     }
  21.     return count;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement