static int min(int a, int b)
{
if (a <= b) {
return a;
}
return b;
}
unsigned int binarytree_minimum_depth_recursive(const btnode *node)
{
unsigned int depth = 0;
if (node->left && node->right) {
depth = min(binarytree_minimum_depth_recursive(node->left),
binarytree_minimum_depth_recursive(node->right)) + 1;
}
return depth;
}
unsigned int binarytree_minimum_depth(const binarytree *tree)
{
unsigned int depth = 0;
if (tree->root) {
depth = binarytree_minimum_depth_recursive(tree->root);
}
return depth;
}