Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do i implement a FINDMINVALUE into the void deletefrom fucntion. I want to c

ID: 3867233 • Letter: H

Question

How do i implement a FINDMINVALUE into the void deletefrom fucntion. I want to combine the minvalue into the deletefrom function.

void Tree::deleteFrom(TreeNode* startintPoint, int value)

{

//from example in class, deleting a node

if (startintPoint == nullptr)

{

return;

}

else if (startintPoint->left != nullptr && value < startintPoint->value)

{

   deleteFrom(startintPoint->left, value);

}

else if (startintPoint->right != nullptr && value > startintPoint->value)

{

   deleteFrom(startintPoint->right, value);

}

else

{

if (startintPoint->left == nullptr && startintPoint->right == nullptr)

{

delete startintPoint;

startintPoint = nullptr;

}

else if (startintPoint->left == nullptr)

{

TreeNode* temp = startintPoint;

startintPoint = startintPoint->right;

delete temp;

}

else if (startintPoint->right == nullptr)

{

TreeNode* temp = startintPoint;

startintPoint = startintPoint->left;

delete temp;

}

else

{

TreeNode* temp = current(startintPoint->right);

startintPoint->value = temp->value;

deleteFrom(startintPoint->right, temp->value);

  

  

}

}

  

  

}

TreeNode* Tree::findMinValue(TreeNode* startingPoint)

{

TreeNode* current = startingPoint;

  

while (current->left != NULL)

{

current = current->left;

}

  

return current;

Explanation / Answer

void Tree::deleteFrom(TreeNode* startintPoint, int value, TreeNode** minValue)

{

//from example in class, deleting a node

if (startintPoint == nullptr)

{

return;

}

else if (startintPoint->left != nullptr && value < startintPoint->value)

{

deleteFrom(startintPoint->left, value);

}

else if (startintPoint->right != nullptr && value > startintPoint->value)

{

deleteFrom(startintPoint->right, value);

}

else

{

if (startintPoint->left == nullptr && startintPoint->right == nullptr)

{

delete startintPoint;

startintPoint = nullptr;

}

else if (startintPoint->left == nullptr)

{

TreeNode* temp = startintPoint;

startintPoint = startintPoint->right;

delete temp;

}

else if (startintPoint->right == nullptr)

{

TreeNode* temp = startintPoint;

startintPoint = startintPoint->left;

delete temp;

}

else

{

TreeNode* temp = current(startintPoint->right);

startintPoint->value = temp->value;

deleteFrom(startintPoint->right, temp->value);

}

//After deleting a value, updating findMinValue

TreeNode* temp = startintPoint;

  

while (temp->left != NULL)

{

temp = temp->left;

}

*minValue = temp; //update min value to the minvalue

}

}

Before calling this function:

Declaration => TreeNode* minValue = nullptr;

Function call => deleteFrom(root, 10, &minValue); //You should call the function by sending the address of minValue

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote