title: How to remove Specific Node is Binary Search Tree?
body: <p>I am trying to delete the specific Node but I don't see where the problem is.</p>
  
  <p>Actually, I get the Node through the <code>Find()</code> and then delete it with <code>Remove()</code>. </p>
  
  <p>The program crashes whenever <code>Delete()</code> fires.</p>
  
  <pre><code>bool RemoveNode(int key)
  {
      if (IsEmpty())
          return false;
      Node* r = Find(key,root);
      if (r==nullptr)
          return false;
      return Remove(r);
  }
  bool Remove (Node* &amp;r)
  {
      if (r-&gt;left==nullptr &amp;&amp; r-&gt;right ==nullptr)
      {
          delete r;
          r=nullptr;
          return true;
      }
      if (r-&gt;left==nullptr)
      {
          Node* temp = r-&gt;right;
          delete r;
          r=nullptr;
          r=temp;
          return true;
      }
      if (r-&gt;right==nullptr)
      {
          Node* temp = r-&gt;left;
          delete r;
          r=nullptr;
          r=temp;
          return true;
      }
      Node* Max = FindMax(r-&gt;left);
      r-&gt;data = Max-&gt;data;
      Remove(Max);
  
      return true;
  }
  Node* FindMax(Node* r)
  {
      if(r-&gt;right==nullptr)
          return r;
      return FindMax(r-&gt;right);
  }
  Node* Find(int key, Node* &amp;r)
  {
      if (r==nullptr)
          return nullptr;
  
      if (r-&gt;data==key)
          return r;
  
      if (key &lt; r-&gt;data)
          return Find(key,r-&gt;left);
      else
          return Find(key,r-&gt;right);
  }
  </code></pre>