Skip to main content
5 of 5
Repair the unordered list
Toby Speight
  • 88.4k
  • 14
  • 104
  • 327
  • Nested functions are not in the C standard. It is a GCC extension, of a dubious value. Don't do it.

  • Casting malloc is 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 rather than sizeof (type), e.g.

      BTree* node = malloc(sizeof *node);
    

    Among other benefits, this avoids double maintenance.

  • isAVLBalanced seems buggy. It only tests the heights of immediate subtrees of the root. You also need the subtrees themselves to be AVL balanced - i.e. it also needs to be recursive.

  • Stylistically, * shall gravitate to a variable, not to the type. Prefer

      struct BTree *left;
    

    Disclaimer: this is a matter of an (heretical) opinion. You don't want to say that left is a pointer to BTree. You want to say that *left in an expression yields a BTree object.

vnp
  • 58.7k
  • 4
  • 55
  • 144