HCMC University of Technology
Faculty of Computer Science & Engineering
Lab 5 AVL
Question 1. With below init code, Implement the blank methods ( //TODO ):
enum Balance {
LEFT_HIGHER,
EQUAL_HIGHER,
RIHT_HIGHER
};
class TreeNode {
public:
int data;
TreeNode* left = NULL;
TreeNode* right = NULL;
Balance balance = EQUAL_HIGHER;
TreeNode(int key); // TODO
/*
TODO: add any function if need
*/
};
class AVLTree {
public:
TreeNode* root = NULL;
void insert(int data); // TODO: insert a node with data into tree
void remove(int key); // TODO: remove/delete a key of the tree
/*
TODO: add any function if need
*/
};
Question 2. Write a function to build AVL tree from an integer array order by index ascending.
/*
arr: integer array to insert
size: lenght of array arr
*/
AVLTree* buildAVL(int arr[], int size)
Question 3. Write a function to print AVL as tree view.
Example:
Output: