A comb left is a locally complete binary tree (each node has 0 or 2 children) in which each right child of a node is a leaf.
Write a function $\texttt{isLeftComb}$ that checks if a binary tree is a left comb.
Difficulty level
This exercise is mostly suitable for students
int isLeaf(Btree B)
{
return (! B->left && ! B->right);
}
int isLeftComb(Btree B)
{
if(B == NULL)
return 1;
if(isLeaf(B))
return 1;
if(B->left && B->right)
return isLeftComb(B->left) && isLeaf(B->right);
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Implementation of a deque using a doubly circular linked list