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)); } }
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)); } }