SOLVED: Write a C++ function to delete the given value’s r…

$30.00

Category:

Description

SOLVED: Write a C++ function to delete the given value’s r…

Write a C++ function to delete the given value’s right child from the binary search tree. The function takes two arguments, tree node and value of the node whose right child has to be deleted.

Also replace the deleted node with minimum value from its left sub tree.

The final tree will not be a valid BST.

ONLY USE THIS FUNCTION HEADER:

void deleteAndReplaceLeftMin(TreeNode *root, int key);

struct TreeNode

{

int key;

TreeNode *left;

TreeNode *right;

TreeNode *parent;

};

For example:

25

/    \

15     30

/ \     / \

8   20  28  35

/ \

27  29

If the key = 25, delete its right child which is 30. Then replace it with the minimum value in the left sub-tree (of 30) which is 27. The final tree is :

25

/    \

15     27

/ \     / \

8   20  28  35

\

29


error: Content is protected !!