static long avl_verify_balance (avl_node * node) { if (!node) { return 0; } else { long lh = avl_verify_balance (node->left); long rh = avl_verify_balance (node->right); if ((rh - lh) != AVL_GET_BALANCE(node)) { return 0; } if (((lh - rh) > 1) || ((lh - rh) < -1)) { return 0; } return (1 + AVL_MAX (lh, rh)); } }
int avl_verify (avl_tree * tree) { if (tree->length) { avl_verify_balance (tree->root->right); avl_verify_parent (tree->root->right, tree->root); avl_verify_rank (tree->root->right); } return (0); }
static long avl_verify_balance (avl_node * node) { if (!node) { return 0; } else { long lh = avl_verify_balance (node->left); long rh = avl_verify_balance (node->right); if ((rh - lh) != AVL_GET_BALANCE(node)) { fprintf (stderr, "invalid balance at node %p\n", node->key); exit(1); } if (((lh - rh) > 1) || ((lh - rh) < -1)) { fprintf (stderr, "unbalanced at node %p\n", node->key); exit(1); } return (1 + AVL_MAX (lh, rh)); } }