title: Binary Search Tree Delete Node With One Child
body: <p>I have a binary search tree and when I try to do the case where you delete a node with a single child, you delete that node and move the child node in it's place. I have the code for it but it's giving me a bad pointer whenever I do it.</p>
  
  <p>This is the segment of the code</p>
  
  <pre><code>else if((root-&gt;Left != NULL) != (root-&gt;Right != NULL)){ //Checks if it's a on child node
      if(root-&gt;Left != NULL){ //If it has a left child, attempts to move the left child to existing node
          delete root;
          root = root-&gt;Left;
      }
      else{ //If it is right child, attempts to move right child to existing node
          delete root;
          root = root-&gt;Right;
      }
  }
  </code></pre>
  
  <p>The struct has values</p>
  
  <pre><code>DATA_TYPE Value;
  TreeNode* Left;
  TreeNode* Right;
  </code></pre>
  
  <p>I know I'm allocating it wrong from the debugger, so what's the correct way to move the node?</p>