void BST::DeleteNode(TreeData El, int& Success)
{
  DeleteHelp(GetRoot(), El, Success);
}

NodePtr BST::DeleteMin(NodePtr Ptr)
{
  NodePtr Temp;
  if (Ptr -> Left != NULL)
    return DeleteMin(Ptr -> Left);
  else
  {
    Temp = Ptr;
    Ptr = Ptr -> Right;
    return Temp;
   }
}

void BST::DeleteHelp(NodePtr Ptr, TreeData El, int& Success)
{
  NodePtr Temp;

  if (Ptr == NULL)
    Success = False;
  else if (El < Ptr -> Left -> Info)
    DeleteHelp(Ptr -> Left, El, Success);
  else if (El > Ptr -> Left -> Info)
    DeleteHelp(Ptr -> Right, El, Success);
  else
  {
    Temp = Ptr;
    if (Ptr -> Left == NULL)
      Ptr = Ptr -> Right;
    else if (Ptr -> Right == NULL)
      Ptr = Ptr -> Left;
    else
    {
      Temp = DeleteMin(Ptr -> Right);
      Ptr -> Info = Temp -> Info;
    }

    delete Temp;
  }
}


Return to CIS 350 Index Page