Ejemplo n.º 1
0
Archivo: rbt.c Proyecto: 1587/ltp
int rbnode_depth(rb_node * node)
{
	/* Recursively determine the depth of the left and right
	 * subtrees
	 */
	int irightdepth = (node->right) ? rbnode_depth(node->right) : 0;
	int ileftdepth = (node->left) ? rbnode_depth(node->left) : 0;

	/* Return the maximal child depth + 1 (the current node) */
	return ((irightdepth >
		 ileftdepth) ? (irightdepth + 1) : (ileftdepth + 1));
}
Ejemplo n.º 2
0
/*!
 * Calculate the depth of the sub-tree spanned by the given node
 *
 * \param node The sub-tree root
 *
 * \return The sub-tree depth
 */
int rbnode_depth
    (
    rbnode_t * node
    )
    {
    /* Recursively calculate the depth of the left and right sub-trees */

    int  iRightDepth = (node->right) ? rbnode_depth(node->right) : 0;

    int  iLeftDepth = (node->left) ? rbnode_depth(node->left) : 0;

    /* Return the maximal child depth + 1 (the current node) */
    return ((iRightDepth > iLeftDepth) ?
            (iRightDepth + 1) : (iLeftDepth + 1));
    }
Ejemplo n.º 3
0
/*!
 * Get the depth of the tree [takes O(n) operations]
 *
 * \param tree The tree
 *
 * \return The length of the longest path from the root to a leaf node
 */
int rbtree_depth
    (
    rbtree_t * tree
    )
    {
    if (!(tree->root))
        return 0;
    return rbnode_depth(tree->root);
    }