Question: Please read the prompt carefully : Use C++ Write three functions: Node* rotateLeft(Node *node); Node* rotateRight(Node *node); Node* rotateLeftRight(Node *node); These functions will take a
Please read the prompt carefully :
Use C++
Write three functions:
Node* rotateLeft(Node *node); Node* rotateRight(Node *node); Node* rotateLeftRight(Node *node);
These functions will take a node at which point you should perform the respective rotations for the balanced tree and return the new root.
The left right rotation should be performed as a left rotation on node's left child, then a right rotation on node.
The first input in test cases is the number of nodes. The second input is nodes of a tree which are inserted in that order. You don't need to implement insert. You have access to the root of the constructed Binary Search Tree.
We will create the tree for you, then call rotateLeftRight on the root of the tree. We will call in-order traversal to check your output.
The output is an in-order traversal of the tree after the rotation.
We have defined the following C++ Node class for you. The name serves as the value.
class Node { public: std::string name; Node* left = NULL; Node* right = NULL; };
Sample Input1: 3 2 0 1
Sample Output1: 012
Sample Input2: 6 6 7 2 1 4 3
Sample Output2: 123467
Sample Input3: 10 9 4 10 11 6 1 3 7 5 8
Sample Output3: 134567891011
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
