Answered step by step
Verified Expert Solution
Question
1 Approved Answer
five part: AVLTree.cpp // AVLTree.h // Node.cpp // main.cpp //Node.h class AVLTree The following functions are the minimum requirements for the AVL class. You can
five part: AVLTree.cpp // AVLTree.h // Node.cpp // main.cpp //Node.h
class AVLTree The following functions are the minimum requirements for the AVL class. You can add any function from Assignment 2 to this class. You should modify the BSTree insert function so that the tree remains balanced after each insertion Required Public Member Functions void insert(const string &): Insert an item to the binary search tree and perform rotation if necessary. int balanceFactor (Node*): Return the balance factor of a given node void printBalanceFactors(): Traverse and print the tree in inorder notation. Print the string followed by its balance factor in parentheses followed by a, and one space. void visualizeTree (const string &):Generate dotty file and visualize the tree using dotty program. Call this function before and after rotation Recommended Private Helper Functions These helper functions are recommended, but you can change them or add other helper functions if necessary. findUnbalancedNode: Find and return the closest unbalanced node (with balance factor of 2 or -2) to the inserted node. rotate: Implement four possible imbalance cases and update the parent of the given node. rotateLeft: Rotate the subtree to left at the given node and returns the new subroot. rotateRight: Rotate the subtree to right at the given node and returns the new subroot void printBalanceFactors (Node ) void visualizeTree (ofstream &,Node * Implementation of visualizeTree function void BSTree::visualizeTree (const string &outputFilename) ofstream outFS (outputFilename.c_str )) if (!outFS.is_open ()) coutleft) visualizeTree (outFS,n->left) outFS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started