Answered step by step
Verified Expert Solution
Link Copied!

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 it.I need the full Avltree.t code Thank you so much !!!!!!!!!! This is Avltree.t : #ifndef AVLTREE_T
#define AVLTREE_T
#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 (*precedes)(const BaseData& x, const BaseData& y))
: BinTree ()
{
this->precedes = precedes;
}
template
AvlTree::AvlTree (const AvlTree &initAvlTree)
{
precedes=initAvlTree.precedes;
}
template class BaseData>
bool AvlTree::add(BaseData item)
{
return addAux((GenTree::root), item );
}
template
bool AvlTree::addAux(GtNode *& 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 *p,*piv,*pivParent,*inp,*inParent,*q;
p = new avlNode;
assert(p !=0);
p -> info = item;
p -> leftChild =0;
p -> rightChild =0;
p -> bf =0;
if (rt == NULL)
{
rt = new avlNode;
if (!rt)
return false;
else
{
rt = p;
/// static_cast avlNode *>( rt )-> bf =0;
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 = static_cast avlNode*>(GenTree::root ) ;
piv = static_cast avlNode*>(GenTree::root );
inParent = NULL;
pivParent = NULL;
****Need to be modifi ****// Search for insertion point and pivot node
do
{
if ( inp -> bf !=0)
{
piv = inp;
pivParent = inParent;
}
inParent = inp;
if (precedes(item, inp -> info))
inp = static_cast avlNode*>( inp -> leftChild );
else
inp = static_cast avlNode*>( inp -> rightChild );
}
while (inp !=0); ****Need to be modifi over here****// Insert the node as the left or right child of inParent
if (precedes(item, 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 1 in the direction of the insertion.
q = piv;
do
{
if ( precedes(item, q -> info))
{
q -> bf++;
q = static_cast avlNode*>( q -> leftChild );
}
else
{
q -> bf--;
q = static_cast avlNode*>( q -> rightChild );
}
}
while (q != p); ****Please need to be modifi over here****// Need to rotate? If not, then we're done!//
if (-1= piv -> bf && piv -> bf =1)
return true;
****Please Need to be modifi over here ********************// AVL rotation is necessary. Call on the appropriate
// function, passing one of root, pivParent->leftChild, or
// pivParent->rightChild as the pointer to the pivot node.
if ( precedes(item, piv -> info))
if ( precedes(item, piv -> leftChild -> info))
if ( piv == AvlTree::root )
leftOfLeft( AvlTree::root );
else
if ( piv == pivParent -> leftChild )
{
leftOfLeft(( pivParent->leftChild ));
}
else
{
leftOfLeft(( pivParent->rightChild ));
}
else
if ( piv == GenTree::root )
rightOfLeft( GenTree::root );
else
if ( piv == pivParent->leftChild )
{
rightOfLeft( pivParent -> leftChild );
}
else
{
rightOfLeft( pivParent->rightChild );
}
else
// if (!precedes(item, piv->leftChild->info)) wrong
if (!precedes(item, piv -> rightChild -> info))//correct
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 { leftOfRight(pivParent -> rightChild); } return true; } m !!!sorry Rest of the code screenshot picture format bcz I'm unable to paste on chegg !!!!!
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions