title: Making a delete function for a binary search tree in C++
body: <p>Edited*: I'm working on the delete function for a binary search tree. I'm just working on the first case right now. I think this is correct, but I'm wondering if it can be done recursively, or more efficiently. Any help is appreciated. Assume BSTSearch searches for a node, <code>isLeaf</code> returns true if the node is a leaf, and each node has a pointer that allows them access to their parent.</p>
  
  <pre><code>void
  BinarySearchTree::BSTDelete(int x, BSTNode *node){
  
      BSTNode *deleteNode;
      deleteNode = BSTSearch(x,node); 
  
      if(isLeaf(deleteNode)){
  
          if(deleteNode-&gt;sortkey &gt; (deleteNode-&gt;parent)-&gt;sortkey){
               delete (deleteNode-&gt;parent)-&gt;right;
              (deleteNode-&gt;parent)-&gt;right = NULL;
          }
  
          else{
              delete (deleteNode-&gt;parent)-&gt;left;
              (deleteNode-&gt;parent)-&gt;left = NULL;  
          }
      }
  </code></pre>