Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here\'s the code I\'ve come up with for the right rotate function, but somehow i

ID: 3730282 • Letter: H

Question

Here's the code I've come up with for the right rotate function, but somehow it is wrong?

void right_single(Node *& tmp)

{

Node *& tmp2 = tmp->left->right;

tmp->left->right = tmp;

tmp = tmp->left;

tmp->right->left = tmp2;

}

Right Single Rotate node: Pointer Reference to node Arguments Return Type None Description Prforms 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 variable

Explanation / Answer

Please find my implementation.

void *right_single(Node *&y)
{
Node *x = y->left;
Node *T2 = x->right;

// Perform rotation
x->right = y;
y->left = T2;

// Update heights
y->height = max(height(y->left), height(y->right))+1;
x->height = max(height(x->left), height(x->right))+1;

// Return new root
return x;
}