Skip to main content
2 of 5
edited body
vnp
  • 58.7k
  • 4
  • 55
  • 144
  • 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) rathre than sizeof(type), e.g.

      BTree* node = malloc(sizeof(*node));
    

    Among other benefits, it avoids double maintenance.

  • isAVLBalanced seems 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. 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 anexpression yields a BTree object.

vnp
  • 58.7k
  • 4
  • 55
  • 144