title: Find the parent node of a node in binary search tree
body: <p>So I want to find the parent node of a Node in a binary tree.
  Suppose that I input 30,15,17,45,69,80,7 in the tree through a text file. </p>
  
  <p>The tree should be</p>
  
  <pre><code>                 30
               15       45
            7      17       69
                                 80
  </code></pre>
  
  <p>And here is my code :</p>
  
  <pre><code>Node*  BST::searchforparentnode(Node* pRoot, int value)
  {
     if(pRoot-&gt;pleft == NULL &amp;&amp; pRoot-&gt;pright == NULL)
      return NULL;
  
     if(pRoot-&gt;pleft-&gt;value == value || pRoot-&gt;pright-&gt;value == value)
      return pRoot;
  
     if(pRoot-&gt;value &gt; value)
      return searchforparentnode(pRoot-&gt;pleft,value);
  
     if(pRoot-&gt;value &lt; value)
      return searchforparentnode(pRoot-&gt;pright,value);
  </code></pre>
  
  <p>}</p>
  
  <p>In this case i'm not consider if the user input the value of the Root node.</p>
  
  <p>Thing is, when I input 15,17,7, all the value in the left branch of Root node, it came out ok. But when i want to find parent Node of the values from the right branch  (69,80) EXCEPT for 45, the program stop running.</p>
  
  <p>Any idea about what caused this error guys? Thanks for reading.</p>