Function that returns number of nodes from a tree that have the two Esq fields and dir different from null

Asked

Viewed 364 times

0

I have a binary search tree in which I created a function that should return the amount of nodes that have both children (different dir and Esq NULL fields), but my function does not give the expected value.

The order of insertion is as follows: 3,5,2,4,7,0,2,8,7,9 In my view, should return 4, but is only returning the value 3.

int getLeafCount(ArvBinaria  *a){
if(a == NULL)       
return 0;
else if (a->sae != NULL && a->sad!=NULL)      
return 1 + getLeafCount(a->sae)+ getLeafCount(a->sad);   
}
  • How does the tree behave in relation to repetitions ? Both the 2 like the 7 has repetitions

  • Depending on the implementation, you can’t tell if the problem is there or elsewhere, or if, based on your algorithm, your interpretation is wrong.

  • I looked here and really the repetition influences, without it the implementation works. For the case that I am working is enough, but I will try to leave in a way that accepts the repetition, vlw

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.