public void colorRange ( Color theColor, K minValue, K maxValue ) { /** set the
ID: 3838048 • Letter: P
Question
public void colorRange ( Color theColor, K minValue, K maxValue ) {
/** set the color of every node that is greater-than-or-equal-to minValue
* but less-than maxValue to be the given color
*/
}
public void deleteSmall ( K key )
{
/** Remove from the tree every node that is less-than-or-equal-to than the given key . To remove these keys you should directly alter the pointers in the tree using setLeft and setRight methods to splice out the small values*/
}
}
Explanation / Answer
You have not provided enough information on the question to give you complete code that you can put in your solution. So, I'm using whatever you have provided to give you the algorithm of how to solve this problem.
colorRange ( Color theColor, K minValue, K maxValue )
1. iterate through every node
if node.value >= minValue AND node.value <=maxValue
node.color = theColor
Then let's look at the deleteSmall function. If this is a BST, then we can replace the deleted node with the smallest value from right subtree.
deleteSmall ( K key )
1. iterate through every node
if node.value <= key
to_replace_node = findsmallestnode(node.rightsubtree)
to_replace_node.parent.setLeft = "NULL"
if (node.parent.left == node)
parent.setLeft = to_replace_node
else
parent.setRight = to_replace_node
This helps you implement the code. If you need further help, please post again with the complete question including the previous codes. Hope this helps.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.