title: insertion binary search tree in C
body: <p>I've been stuck on the insertion part of the binary search tree. I get so confused with nested structs. The basic idea of this program is to create a bst that is able to hold names and double values which get stored by value (obviously).</p>
  
  <p>Example: I want to store  </p>
  
  <p>Jane 3.14</p>
  
  <p>John 3.233</p>
  
  <p>Luke 6.4</p>
  
  <p>Mike 1.4 </p>
  
  <p>so the bst would look like</p>
  
  <pre><code>                 3.14
                   /   \
                1.4    3.233
                         \
                          6.4
  </code></pre>
  
  <p>however I'm having trouble with the insertHelper recursion portion of the code. The hash table is a bonus part of the code that I'll try implementing at a later time. Thank you for your help!</p>
  
  <pre><code>typedef struct name_val // holds name and value
  {
      char *name;
      double value;
  }NAME_VAL;
  
  typedef struct node //binary search tree
  {
      NAME_VAL *nV;
      struct node *left;
      struct node *right;
  }NODE;
  
  struct tmap_struct  //handle for bst and hashtable
  {
      int nL; //nodes on left
      int nR; //nodes on right
      NODE *root;
      NODE **table;
  };
  
  
  int tmap_insert(TMAP_PTR hashTree, char * name, double val)
  {
      if(hashTree-&gt;root == NULL)
      {
          NODE *bst = (NODE *)malloc(sizeof(NODE));
          NAME_VAL *root = (NAME_VAL *)malloc(sizeof(NAME_VAL));
          bst-&gt;nV = root;
          bst-&gt;nV-&gt;value = val;
          strcpy(bst-&gt;nV-&gt;name, name);
          hashTree-&gt;root = bst;
          hashTree-&gt;nL = 0;
          hashTree-&gt;nR = 0;
      }
  
      else 
          insertHelper(hashTree-&gt;root, val, name);
  
  }
  
  void insertHelper(TMAP_PTR hashTree, int val, char * name)
  {
      if(val &lt; hashTree-&gt;root-&gt;nV-&gt;value)
      {
          if(hashTree-&gt;root-&gt;left == NULL)
          {
              hashTree-&gt;root-&gt;left = (NODE *)malloc(sizeof(NODE));
              hashTree-&gt;root-&gt;left-&gt;nV = (NAME_VAL *) malloc(sizeof(NAME_VAL));
              strcpy(hashTree-&gt;root-&gt;left-&gt;nV-&gt;name, name);
              hashTree-&gt;root-&gt;nV-&gt;value = val;
              (hashTree-&gt;nL)++;
          }
  
          else
              insertHelper(hashTree-&gt;root-&gt;left, val, name);
      }
  
      else
      {
          if(hashTree-&gt;root-&gt;right == NULL)
          {
              hashTree-&gt;root-&gt;right = (NODE *)malloc(sizeof(NODE));
              hashTree-&gt;root-&gt;right-&gt;nV = (NAME_VAL *)malloc(sizeof(NAME_VAL));
              strcpy(hashTree-&gt;root-&gt;left-&gt;nV-&gt;name,name);
              hashTree-&gt;root-&gt;nV-&gt;value = val;
              (hashTree-&gt;nR)++;
          }
  
          else
              insertHelper(hashTree-&gt;root-&gt;right, val, name);
      }
  }
  </code></pre>