title: Binary Search Tree - Insert
body: <p>I am trying to write a function that inserts a value into a binary tree. I got this so far:</p>
  
  <pre><code>struct node
  {
       int data;
       struct node* left;
       struct node* right;
  };
  
  
  struct node* newNode(int data)
  {
       struct node* node = (struct node*)
       malloc(sizeof(struct node));
       node-&gt;data = data;
       node-&gt;left = NULL;
       node-&gt;right = NULL;
  
       return(node);
  }
  
  // Insert
  struct node* insert (struct node* node, int data)
  {
      if (node == NULL)
          node-&gt;data=data;
      else 
      {
        if (data &lt; node-&gt;data)
           node-&gt;left = insert(node-&gt;left, data);
        else
           node-&gt;right = insert(node-&gt;right ,data);
      }
      node-&gt;left = NULL;
      node-&gt;right = NULL;
      return node;
  }
  </code></pre>
  
  <p>But everytime I ran it, it stops working. Therefore I think there must be something wrong with my insert function. Any ideas?</p>