Question: I need help with the to do part in the picture, question is mentioned below. Thank you so much for the answer. In this question,
I need help with the to do part in the picture, question is mentioned below. Thank you so much for the answer.
In this question, you have to perform add on AVL tree. Note that:
When adding a node which has the same value as parent node, add it in the right sub tree.
Your task is to implement function: insert. You could define one or more functions to achieve this task.
#include
#include
#include
using namespace std;
#define SEPARATOR ##
enum BalanceValue
LH
EH
RH
;
void printNSpaceint n
for int i ; i n ; i
cout ;
void printIntegerint &n
cout n ;
template
class AVLTree
public:
class Node;
private:
Node root;
protected:
int getHeightRecNode node
if node NULL
return ;
int lh thisgetHeightRecnodepLeft;
int rh thisgetHeightRecnodepRight;
return lh rh lh : rh;
public:
AVLTree : rootnullptr
~AVLTree
int getHeight
return thisgetHeightRecthisroot;
void printTreeStructure
int height thisgetHeight;
if thisroot NULL
cout "NULL
;
return;
queue q;
qpushroot;
Node temp;
int count ;
int maxNode ;
int level ;
int space pow height;
printNSpacespace ;
while qempty
temp qfront;
qpop;
if temp NULL
cout ;
qpushNULL;
qpushNULL;
else
cout tempdata;
qpushtemppLeft;
qpushtemppRight;
printNSpacespace;
count;
if count maxNode
cout endl;
count ;
maxNode ;
level;
space ;
printNSpacespace ;
if level height
return;
void insertconst T &value
TODO
class Node
private:
T data;
Node pLeftpRight;
BalanceValue balance;
friend class AVLTree;
public:
NodeT value : datavalue pLeftNULL pRightNULL balanceEH
~Node
;
;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
