How would you write this function in C++ given the pseudo code. Right Single Rot
ID: 3735630 • Letter: H
Question
How would you write this function in C++ given the pseudo code.
Right Single Rotate Arguments Return Type Description node: Pointer Reference to node None Performs a Right single rotate on a left heavy tree Pseudocode 1. 2. 3. 4. Assign a temporary variable to node's left's right child Set nodes left's right to point to node. Point node to node's left Point nodes rights left to the temporary variableExplanation / Answer
void singleRightRotate(node) { temp = node->left->right; //assign temporary variable to node's left's right node while (temp->right) //iterates all right nodes until it finds child node temp = temp->right; //set temporary node to node's left's right child a = head->left->right; //point node's left's right node = node->left; //point node to node's left temp->left = a->left; //point nodes rights left to temp variable }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.