title: Function to add node to a tree
body: <p>This question is related to a Binary Search tree. Here is the definition of a node that I am using </p>
  
  <pre><code>struct _Node
  {
      _Node *Parent;
      int Data;
      _Node *Left;
      _Node *Right;
  };
  </code></pre>
  
  <p>Now here is the definition of the function to add a node once a root is created</p>
  
  <pre><code>void AddNode(_Node *Incoming, _Node *currentNode)
  {
  
              if(!currentNode)
              {
                  currentNode = Incoming;
              }
              else if(currentNode-&gt;Data &gt;= Incoming-&gt;Data)
              {
                  Incoming-&gt;Parent = currentNode;
                  AddNode(Incoming, currentNode-&gt;Left);
              }
              else if(currentNode-&gt;Data &lt; Incoming-&gt;Data)
              {
                  Incoming-&gt;Parent = currentNode;
                  AddNode(Incoming, currentNode-&gt;Right);
              }
  
  }
  </code></pre>
  
  <p>AddNode function is based on a recursive approach. Main code is </p>
  
  <pre><code>_Node *Root= new _Node;
  Root-&gt;Data = 50;
  Root-&gt;Parent = nullptr;
  Root-&gt;Left = nullptr;
  Root-&gt;Right = nullptr;
  
  
  _Node *Node2 = new _Node;
  Node2-&gt;Data = 25;
  Node2-&gt;Parent = nullptr;
  Node2-&gt;Left = nullptr;
  Node2-&gt;Right = nullptr;
  _Node *Node3 = new _Node;
  
     AddNode(Node2, Root);
  </code></pre>
  
  <p>Problem:
  Once I come out of the add node function I find that Root node doesnot have a Left or Right Child set to Node2. According to me as pointer to a node is passed each time I should have got the node added to the Root correctly. this is not happening. Can you please help me out here to understand what mistake I am making?</p>