Beispiel #1
0
void DeleteNode(TreeNode*& tree)
// Deletes the node pointed to by tree.
// Post: The user's data in the node pointed to by tree is no 
//       longer in the tree.  If tree is a leaf node or has only 
//       non-NULL child pointer the node pointed to by tree is 
//       deleted; otherwise, the user's data is replaced by its 
//       logical predecessor and the predecessor's node is deleted.
{
  ItemType data;
  TreeNode* tempPtr;

  tempPtr = tree;
  if (tree->left == NULL)
  {
    tree = tree->right;
    delete tempPtr;
  }
  else if (tree->right == NULL)
  {
    tree = tree->left;
    delete tempPtr;
  }
  else
  {
    GetPredecessor(tree->left, data);
    tree->info = data;
    Delete(tree->left, data);  // Delete predecessor node.
  }
}
Beispiel #2
0
void Tree::DeleteNode(TreeNode *&pTree){

    Student data;
    TreeNode* temp;

    temp = pTree;

    if(pTree->m_left == nullptr){
        pTree = pTree->m_right;
        delete temp;
    }
    else if(pTree->m_right == nullptr){
        pTree = pTree->m_left;
        delete temp;
    }
    else{
        GetPredecessor(pTree->m_left,data);
        pTree->m_student = data;
        Delete(data.getID(),pTree->m_left);
    }
}