Binary Search Tree (search function)
<pre><code>template &lt;class T&gt;
struct TreeNode{
  string value;
  T key;
  TreeNode&lt;T&gt; *Parent;
  TreeNode&lt;T&gt; *LeftChild;
  TreeNode&lt;T&gt; *RightChild;
  TreeNode (T k,string Val)
  {
           this-&gt;value=Val;
           this-&gt;key=k;
           this-&gt;Parent=NULL;
           this-&gt;LeftChild=NULL;
           this-&gt;RightChild=NULL;
  }
};

template &lt;class T&gt;
class BinaryTree{
  private:
       TreeNode&lt;T&gt; *Root;        
  public:  
       BinaryTree();
       ~BinaryTree();
       void insertNode(T Key,string Val);
       void deleteNode(T Key);
       string searchNode(T Key);
       void UpdateKey(T newkey,T oldkey);
       int Height(TreeNode&lt;T&gt; *node);
       int height();
};




template &lt;class T&gt;
string BinaryTree&lt;T&gt;::searchNode(T Key)
{        
TreeNode&lt;T&gt; *temp=Root;
while (temp!=NULL)
{
      if (temp-&gt;key==Key)
      {
          cout&lt;&lt;temp-&gt;key&lt;&lt;endl;                             
          return temp-&gt;value;
      }
      if (temp-&gt;key&gt;Key)
      {
          temp=temp-&gt;LeftChild;
      }
      else if (temp-&gt;key&lt;Key)
      {
           temp=temp-&gt;RightChild;
      }                  
}     
return "\0";
}
</code></pre>

<p>I am making a binary search tree. But when I run my search function, it always returns NULL value even when the value exists in the tree. Either my constructor is not right or there is something wrong with my search function. I can't seem to figure out the problem.
Here is the constructor:</p>

<pre><code>template &lt;class T&gt;
BinaryTree&lt;T&gt;::BinaryTree()
{
Root=NULL;                       
ifstream fin;
fin.open("names.txt");
string buffer;
T buff;
while (!fin.eof())
{
      getline(fin,buffer,'~');
      fin&gt;&gt;buff;

      TreeNode&lt;T&gt; *temp,*temp1;
      temp=Root;
      temp1=temp;
      while (temp!=NULL)
      {
          temp1=temp;  
          TreeNode&lt;T&gt; *Right=temp-&gt;RightChild;
          TreeNode&lt;T&gt; *Left=temp-&gt;LeftChild;
          if (temp-&gt;key&gt;buff)
          {
              temp=temp-&gt;LeftChild;
          }
          else if (temp-&gt;key&lt;buff)
          {
              temp=temp-&gt;RightChild;
          }
          else
          {
              temp=temp-&gt;LeftChild;
          }
      }
      if (temp!=Root)
      temp-&gt;Parent=temp1;
      temp=new TreeNode&lt;T&gt;(buff,buffer);
}
fin.close();
}
</code></pre>
