Question: Please code in C + + . I need help on coding an ExtendedRBTNode.h file and an ExtendedRedBlackTree.h file. Thank you 8 . 1 2
Please code in C I need help on coding an ExtendedRBTNode.h file and an ExtendedRedBlackTree.h file. Thank you LAB: Redblack tree Nth largest operation Step : Inspe tep : Run tests in develop mode and submit mode Then Deter us acr xSis n in cters talese return false; not case protected: virtual void InsertNodeBSTNode node override BinarySearchTree: insertion starts with the standard BST insertion Color the node red, then balance RBTNode node color RBTNode : : REDCOLOR; InsertionBalance RBTNodenode ; virtual BSTNode MakeNewNodeint key override return new RBTNodekey; virtual bool RemoveNodeBSTNode bstNode override if lbstNode RBTNode node RBTNode bstNode; if nodeGetLeft && nodeGetRight f RBTNode predecessorNode RBTNode nodeGetLeft; while predecessorNodeGetRight predecessorNode RBTNode predect predecessorNode RBTNode predecessorNodeetRight ; Get predecessor's key, then recursively remove the predecessor node int predecessorKey predecessorNodeGetKey Remove Assign the node's key with the nowremoved predecessor node's key return true if nodeIsBlack PrepareForRemoval node; BinarySearchTree: : RemoveNodenode One special case if the root was changed to red RBTNode rootNode RBTNode GetRoot if rootNode && rootNodeIsRed rootNodeColor RBTNode: : BLACKCOLOR root return true; public: RedBlackTree Note: Parent class's constructor does all needed work void InsertionBalanceRBTNode node If If node is the tree's root, then color node black and return nodeCOlor RBTNode: : BLACKCOLOR: return; Pointer to parent node is needed for remaining operations RBTNode parent RBTNode nodeGetParent If parent is black, then return without any changes return; pointers tograndparent and uncle are needed for remaining operations RBTNode grandparent nodeGetGrandparent ; RBTNode uncle nodeGetuncle; If parent and uncle are both red, then color parent and uncle black, if uncle && uncleIsRed parentcolor unclecolor RBTNOde : : BLACKCOLOR; grandparent COlor RBTNode: : REDCOLOR: return; If node is parent's right child and parent is grandparent's left child, then rotate left at parent, update node and parent to point to if node parentGetRight && parent grandparentGetLeft Rotateleft parent node parent ; parent RBTNode nodeGetParent Else if node is parent's left child and parent is grandparent's right child, then rotate right at parent, update node and parent to point to l parent and grandparent, respectively RotateRight parent node parent parent RBTNode nodeGetParent ; Color parent black and grandparent red parent COlor RBTNOde:: BLACKCOLOR; If node is parent's Left child, then rotate right at grandparent, If otherwise rotate Left at grandparent RotateRightgrandparent else el RotateLeft grandparent: bool IsNullorBlackRBTNode node if node nullptr return nodeIsBlack ; bool IsNotNullandRedRBTNode node if node nullptr return false; return node Is Red;Current file: BSTNodeVisitor.h
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
