Question: Please solve part c, thanks! 3. (15 points - Completeness) Implementing AVL rotation and insertion: Suppose you've been given the following code class AVLNode (

 Please solve part c, thanks! 3. (15 points - Completeness) Implementing

AVL rotation and insertion: Suppose you've been given the following code class

AVLNode ( public: AVLNode left; AVLNode right; AVLNode * parent; int data;

int height; /Height of subtree rooted here. A single node has height

Please solve part c, thanks!

3. (15 points - Completeness) Implementing AVL rotation and insertion: Suppose you've been given the following code class AVLNode ( public: AVLNode left; AVLNode right; AVLNode * parent; int data; int height; /Height of subtree rooted here. A single node has height 1 / AVLNode (const int d) : data (d), height (1) left-right-parent-nullptr; ) private: void adjustHeight /*Adjust the height of this node to reflect the height of the subtrees, which are assumed correct. Implementation given below */ Assuming the heights of the children are set correctly, adjust the height of the subtree rooted at this node/ void AVLNode::adjustHeight( int left, right 0; if (this->left != nullptr) left if (this->right != nullptr) right height max (left, right) + 1; this->left->height; this->right->height; class AVLTree ( public: AVLNode root AVLTree () { root nul !ptr; } AVLTree) boolean insert(int data); /*Destructor not shown /implement in part (c) / private: void rotateLeft (AVLNode top); void rotateRight (AVLNode * top) void doubleRotateLeftKink (AVLNode top) /* implement this in part (b)/ void doubleRotateRightKink (AVLNode top) /* implementation not shown / AVLNode* findInsertionPoint (int data) const; helper method defined below / /implement this in part (a)/ /*implementation not shown * (a) Implement rotateLeft in C++ Rotate left e top. * The node top->parent (if present) should remain an ancestor of all of its * descendants and top's location in the tree should be replaced by top-right. void AVLTree: :rotateLeft (AVLNode top) (b) Implement doubleRotateLeftKink in C++. You may use the methods rotateLeft and rotateRight in your implementation *Perform a double rotation involving top, top->left, and top->left->right. *The node top->parent (if present) should remain an ancestor of all of its * descendants. void AVLTree: :doubleRotateLeftKink (AVLNode top) (c) Implement insert for an AVL tree in C++. You may assume that all of the other code from the AVLNode class and the AVL Tree class is available to you, including the private helper function findInsertionPoint, whose implementation is given below. The box for the insert code is on the next page Return a pointer to the node where this data element should be inserted or nullptr if the data element is already in the tree. Precondition: The tree is not empty AVLNode AVLTree::findInsertionPoint (int d) const AVLNode * curr = root; AVLNode * prev nullptr; while (curr!null) f prevcurr if (d data) curr = curr->left; else if (curr->data right; else return nullptr: 1/ already in the tree return previ Returns false if data is already in the tree, otherwise inserts * data into the tree and returns true. bool AVLTree::insert (int data) (

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!