March 2019
Intermediate to advanced
336 pages
9h 9m
English
The removeRNode method removes the node from the tree and balances the tree. This method takes rootNode, which is a TreeNode pointer, and the key value. This method returns a TreeNode pointer and Boolean value if RNode is removed, as shown in the following code snippet:
//removeRNode methodfunc removeRNode(rootNode *TreeNode, key KeyValue) (*TreeNode, bool) { if rootNode == nil { return nil, false } if rootNode.KeyValue.EqualTo(key) { switch { case rootNode.LinkedNodes[0] == nil: return rootNode.LinkedNodes[1], false case rootNode.LinkedNodes[1] == nil: return rootNode.LinkedNodes[0], false } var heirNode *TreeNode heirNode = rootNode.LinkedNodes[0] for heirNode.LinkedNodes[1] != nil { heirNode = heirNode.LinkedNodes[1] ...Read now
Unlock full access