Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please Modifi This Avltree.t file for me don't change any code on this file Just look at the comment indicated as like this / /
Please Modifi This Avltree.t file for me don't change any code on this file Just look at the comment indicated as like this" and modifie itI need the full Avltree.t code Thank you so much This is Avltree.t : #ifndef AVLTREET
#define AVLTREET
#include
using std::cout;
using std::cin;
using std::endl;
#include
#include
#ifndef leftChild
#define leftChild firstChild
#endif
#ifndef rightChild
#define rightChild sibling
#endif
template
AvlTree::
AvlTree bool precedesconst BaseData& x const BaseData& y
: BinTree
thisprecedes precedes;
template
AvlTree::AvlTree const AvlTree &initAvlTree
precedesinitAvlTree.precedes;
template class BaseData
bool AvlTree::addBaseData item
return addAuxGenTree::root item ;
template
bool AvlTree::addAuxGtNode & rt BaseData item
Need to be modifi over here Note that since the pointer rt will be altered by this
function, it must be passed by reference.
avlNode temp;
temp new avlNode;
avlNode ppivpivParentinpinParentq;
p new avlNode;
assertp ;
p info item;
p leftChild ;
p rightChild ;
p bf ;
if rt NULL
rt new avlNode;
if rt
return false;
else
rt p;
staticcast avlNode rt bf ;
return true;
Need to be modifi over here Pointer inp keeps track of insertion point, with its
parent inparent. Pointer piv keeps trace of pivot node,
with its parent pivParent.
inp staticcast avlNodeGenTree::root ;
piv staticcast avlNodeGenTree::root ;
inParent NULL;
pivParent NULL;
Need to be modifi Search for insertion point and pivot node
do
if inp bf
piv inp;
pivParent inParent;
inParent inp;
if precedesitem inp info
inp staticcast avlNode inp leftChild ;
else
inp staticcast avlNode inp rightChild ;
while inp ; Need to be modifi over here Insert the node as the left or right child of inParent
if precedesitem inParent info
inParent leftChild p;
else
inParent rightChild p;
Need to be modifi over here Now recompute the balance factors between piv and inParent.
By definition of a pivot node, all these balance factors must
change by in the direction of the insertion.
q piv;
do
if precedesitem q info
q bf;
q staticcast avlNode q leftChild ;
else
q bf;
q staticcast avlNode q rightChild ;
while q p; Please need to be modifi over here Need to rotate? If not, then we're done!
if piv bf && piv bf
return true;
Please Need to be modifi over here AVL rotation is necessary. Call on the appropriate
function, passing one of root, pivParentleftChild, or
pivParentrightChild as the pointer to the pivot node.
if precedesitem piv info
if precedesitem piv leftChild info
if piv AvlTree::root
leftOfLeft AvlTree::root ;
else
if piv pivParent leftChild
leftOfLeft pivParentleftChild ;
else
leftOfLeft pivParentrightChild ;
else
if piv GenTree::root
rightOfLeft GenTree::root ;
else
if piv pivParentleftChild
rightOfLeft pivParent leftChild ;
else
rightOfLeft pivParentrightChild ;
else
if precedesitem pivleftChildinfo wrong
if precedesitem piv rightChild infocorrect
if piv GenTree::root
rightOfRight GenTree::root ;
else
if piv pivParent leftChild
rightOfRight pivParent leftChild ;
else
rightOfRight pivParent rightChild ;
else
if piv GenTree::root
leftOfRight GenTree::root ;
else
if piv pivParent leftChild
leftOfRight pivParent leftChild else leftOfRightpivParent rightChild; return true; m sorry Rest of the code screenshot picture format bcz Im unable to paste on chegg
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