Question: Write a function to find the minimum and maximum nodes within a BST and then replace the maximum node with the minimum node. Then, delete

Write a function to find the minimum and maximum nodes within a BST and then replace the maximum node with the minimum node. Then, delete the minimum node.

You should call the provided functions, findMinNode(node) and findMaxNode(node) to find the minimum node and maximum nodes in the tree; Call these functions within the function you write.

Header: void replaceMaxWithMin(TreeNode *root);

TreeNode struct:

struct TreeNode{

int key;

TreeNode *leftChild;

TreeNode *rightChild;

TreeNode *parent;

};

Functions to call to get the min and max:

TreeNode* findMinNode(TreeNode* min){

while (min->leftChild != NULL){ min = min->leftChild; }

return min;

}

TreeNode* findMaxNode(TreeNode* max){

while (max->rightChild != NULL){ max = max->rightChild; }

return max;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!