Binary Search Tree insert while keeping track of parent for node to be added This question has a follow up question:
  Binary Search Tree insert while keeping track of parent for node to be added - iteration 2


I am implementing a red black tree for fun and am wondering how I should modify my basic BST insert. Note: this happens before the red black tree rules are applied, it just finds the correct place within the tree to add the node, places it, sets references, value and defaults the color to RED. I am mainly struggling to see if there may be a better way to tack on the parent reference for the newly added node. The implementation I have here looks ahead one step with a NULL check where a BST insert that does not need to track the parent would not need.

struct node * bstInsert(struct node *n, int x) {

  if (n != NULL) {

    int cmp = (n-&gt;val &lt; x) ? -1 : (n-&gt;val &gt; x);

    if (cmp == -1) {

      if (n-&gt;left == NULL) {
        n-&gt;left = createAChild(n, n-&gt;left, x);
      } else {
        bstInsert(n-&gt;left, x);
      }

    } else if (cmp &gt; 0) {

      if (n-&gt;right == NULL) {
        n-&gt;right = createAChild(n, n-&gt;right, x);
      } else {
        bstInsert(n-&gt;right, x);
      }

    }

  }

  return n;
}

struct node * createAChild(struct node *par, struct node *n, int x) {

  n = malloc(
    sizeof(struct node)
  );
  n-&gt;parent = par;
  n-&gt;left = n-&gt;right = NULL;
  n-&gt;val = x;
  n-&gt;color = RED;

  return n;

}


Is there a cleaner solution to setting the parent reference for the node to be added?
Instead of if (n != NULL) and then indenting the whole code of function, it is better to write:
if (n == NULL) { return NULL; }
The line int cmp = (n-&gt;val &lt; x) ? -1 : (n-&gt;val &gt; x); is very hard to read. 
I suggest finding a better name to cmp - for example isGreater and changing its type to boolean.