0% found this document useful (0 votes)
124 views1 page

AVL Tree Implementation Guide

This document contains instructions for implementing methods for an AVL tree data structure in C++. It provides the starter code for AVL tree nodes and the tree itself, and asks the reader to complete the constructor for nodes, as well as insert and remove methods on the tree. It also asks the reader to write functions to build an AVL tree from an integer array ordered by index, and to print the tree.

Uploaded by

Thắng Huỳnh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views1 page

AVL Tree Implementation Guide

This document contains instructions for implementing methods for an AVL tree data structure in C++. It provides the starter code for AVL tree nodes and the tree itself, and asks the reader to complete the constructor for nodes, as well as insert and remove methods on the tree. It also asks the reader to write functions to build an AVL tree from an integer array ordered by index, and to print the tree.

Uploaded by

Thắng Huỳnh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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:

You might also like