Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Does it make clear how measurements are defined?

Answered: 1 week ago