0

Hey
i want to create a method which counts the nodes from a binary tree that have exactly one child
i did that but it returns error :S
Can anyone tell me what's going wrong ??

Thanks in advance

//Count nodes from BinaryTree1 that have exactly one child
      public static int countNodesOne(BinaryTree2 node)
      {
          if (node == null)
          {
              return 0;
            }
            else
            {
                if (int leftCount = countNodesOne(node.left = 1))
                {
                    else if (int rightCount = countNodesOne(node.right = 1)
                    {
                    return leftCount + rightCount;
                }
            }
        }
    }
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by eleonora
0

if (int leftCount = countNodesOne(node.left = 1))

whats this? = is assignment operator not check for equality

should'nt this statement say:
node.left ==1

0

oh i haven't noticed that
thanks!

but the problem is that it returns an error saying '.class expected' :S
???

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.