Question: Insert( X, T) inserts X into AVL tree T. Please fill blanks in it. struct AVLTreeNode { int Element; struct AVLTreeNode *Left; struct AVL TreeNode



Insert( X, T) inserts X into AVL tree T. Please fill blanks in it. struct AVLTreeNode { int Element; struct AVLTreeNode *Left; struct AVL TreeNode *Right; int Height; }; typedef struct AVLTreeNode *Position, *AVLTree; int Height(AVLTree T) { if (!T) return -1; return T->Height; } int Max(int a, int b) { if (a>b) return a; return b; } AVL Tree Insert(ElementType X, AVL Tree T) { if (T == NULL) { /* Create and return a one-node tree */ T = (AVLTree)malloc(sizeof(struct AVL TreeNode)); T->Element = X; T->Height = 0; T->Left = T->Right = NULL; - } /* End creating a one-node tree */ else if (X Element) { /* handle left insertion */ T->Left = Insert(X, T->Left); if ( (1)__) if ((2) __) /* LL Rotation */ T = SingleRotateWith Left(T); else /* LR Rotation */ T = DoubleRotateWith Left(T); } /* End left */ else if (X> T->Element) { /* handle right insertion */ T->Right = Insert(X, T->Right); if (3) ) if ( (4) ) /* RR Rotation */ if (4) ) /* RR Rotation */ T = SingleRotateWithRight(T); else /* RL Rotation */ T = DoubleRotateWith Right(T); } /* End right */ /* Else X is in the tree already; we'll do nothing */ T->Height = (5) return T; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
