Remove a Node from a binary tree

Please help. What is wrong with my remove function below. Cant seem to figure it out

I seem to be getting an error: The class declaration seems pretty fine. The main issue is to have this remove function to work

void binaryTree::Remove(int) {
  if (node != NULL)
  {
     Node* tmptr = node;
     int rootdata = node->data;
     /int rSubtree;
  }
  {
  // Case 0- no child
  if (node->lChild == NULL && node->rChild == NULL)
  {
      node = NULL;
      //parent-            //set the parent of the node to NULL
      delete node;
  }
  // has one child
  else if (node->lChild == NULL && node->rChild != NULL)
  {
      node = node->rChild;
      node->rChild = NULL;
      delete node;
  }

  else if (node->lChild != NULL && node->rChild == NULL)
  {
      node = node->lChild;`enter code here`
      node->lChild = NULL;
      delete node;
  }
}

Answers


Try swapping node = NULL with delete node; Otherwise you're trying to delete NULL.


Need Your Help

rspec XOR should include

ruby rspec xor

I want to check for the presence of exactly one of two possible strings in my rspec test (XOR).