0
public static boolean what (Node n)
{
   if (n == null)
	return true;
   if (n.getLeftSon()==null && n.getRightSon()==null)
	return true;
   if (n.getRightSon()==null)
	return (n.getNumber() % n.getLeftSon().getNumber() == 0) 
			&&
        what (n.getLeftSon());
   if (n.getLeftSon()==null)
	return (n.getNumber() % n.getRightSon().getNumber() == 0) 
			&&
        what (n.getRightSon());

   return (n.getNumber() % n.getLeftSon().getNumber() == 0) 
     &&   (n.getNumber() % n.getRightSon().getNumber() == 0)
     &&	what (n.getLeftSon()) 
     &&	what (n.getLeftSon());
}

I think that the method checks for sons which are zeros, in case she find out, she return false, else she returns true? right ?

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by javaAddict
0

Returns true if each "father" can be divided by each of their "sons". false even if one of the fathers cannot be divided by theirs sons. If a node is null, it does not check it and returns true.

0

Returns true if each "father" can be divided by each of their "sons". false even if one of the fathers cannot be divided by theirs sons. If a node is null, it does not check it and returns true.

Then if I'll take the tree (attached file) the returns value will be false ?

Attachments tree.JPG 5.75 KB
This question has already been answered. 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.