Write a iterative function singleParent that returns the num

Write a iterative function, singleParent, that returns the number of the nodes in a binary tree that have only one child. in c++

Solution

These method will help you to find the number of nodes having one child node.

public static boolean isOneChild(TreeNode t)
{
if(numberOfChildren(t)==1)
{
return true;
}
else
return false;
}

public static int numberOfChildren (TreeNode t){
int count = 0;
if(t.getLeft() != null ) count++;
if(t.getRight() != null) count++;
return count;
}

Write a iterative function, singleParent, that returns the number of the nodes in a binary tree that have only one child. in c++SolutionThese method will help y

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site