Nested functions are not in the C standard. It is a GCC extension, of a dubious value. Don't do it.
Casting
mallocis a bad practice. First, it is not necessary, and second, it may lead to a hard-to-find bugs.Along the same line, prefer
sizeof(value)rathre thansizeof(type), e.g.BTree* node = malloc(sizeof(*node));Among other benefits, it avoids double maintenance.
isAVLBalancedseems buggy. It only test the heights of an immediate subtrees of the root. You also need the subtrees themselves to be AVL balanced, that is it also needs to be recursive.Stylistically,
*shall gravitate to a variable, not to the type. Preferstruct BTree *left;Disclaimer: this is a matter of an (heretical) opinion. You don't want to say that
leftis a pointer toBTree. You want to say that*leftin anexpression yields aBTreeobject.
vnp
- 58.7k
- 4
- 55
- 144