示例#1
0
void bst_successor(node_t *n)
{
	if (n->children[1])
		return bst_find_minimum(n->children[1]);
	else
		return bst_find_minimum(n->parent->children[1]);
		// go up one level and run bst_find_minimum on that subtree
		// what if the parent doesn't have a right subtree?
}
示例#2
0
TreeNode * bst_find_successor(TreeNode * node) {
    TreeNode * curr = node;

    if (curr->right != NULL) {
        return bst_find_minimum(curr->right);
    }

    TreeNode * parent = curr->parent;
    while (parent != NULL && parent->right == curr) {
        curr = parent;
        parent = parent->parent;
    }

    return parent;
}