This commit is contained in:
Anton Dolozin 2025-11-09 21:12:46 +01:00
parent a8d91996df
commit a480aa16fe

View File

@ -79,15 +79,13 @@ int count_leaves(struct tree* tree){
}
}
int count_non_leaves(struct tree* tree){
int count = 0;
if(tree == NULL){
return count;
if(tree == NULL || (tree->left == NULL && tree->right == NULL)){
return 0;
}
if(tree->left && tree->right){
return count + count_leaves(tree->left) + count_leaves(tree->right);
}
return count+1;
return 1+ count_non_leaves(tree->left) + count_non_leaves(tree->right);
}