March 2019
Intermediate to advanced
336 pages
9h 9m
English
The singleRotation method rotates the node opposite to the specified sub-tree. As shown in the following snippet, the singleRotation function rotates the node opposite the left or right sub-tree. The method takes the pointer to rootNode and a nodeValue integer as parameters and returns a TreeNode pointer:
// single rotation methodfunc singleRotation(rootNode *TreeNode, nodeValue int) *TreeNode {var saveNode *TreeNode saveNode = rootNode.LinkedNodes[opposite(nodeValue)] rootNode.LinkedNodes[opposite(nodeValue)] = saveNode.LinkedNodes[nodeValue] saveNode.LinkedNodes[nodeValue] = rootNode return saveNode}
Read now
Unlock full access