I am trying to create an AVL tree and i am using a dynamic array of pointers to track which nodes are affected by the insertion.My Question is if the deletion of the dynamic array will delete the content of the pointers as well.The code is not finished but i think it will give you an idea of what i mean.If it does not work then how should i do it?Thanks in advance.
treenode *newnode,**roadnodes,*parent ;
int x=(int)log(numberofnodes)+2,l=0 ;
bool *rightorleft,flag=true ;
newnode=new treenode ;
roadnodes=new treenode*[x] ;
rightorleft=new bool[x] ;
newnode->id=i ;
newnode->hl=0;
newnode->hr=0;
newnode->hm=0;
newnode->left=NULL;
newnode->right=NULL ;
if(head==NULL)
{
delete[] roadnodes ;
delete[] rightorleft ;
numberofnodes++ ;
head=newnode ;
return true ;
}
parent=head ;
while(flag)
{
roadnodes[l]=parent ;
if(parent->id>i)
{
if(parent->left)
parent=parent->left ;
else
{
flag=false ;
parent->left=newnode ;
}
rightorleft[l]=true ;
l++ ;
}
else
{
if(parent->right)
parent=parent->right ;
else
{
flag=false ;
parent->right=newnode ;
}
rightorleft[l]=false ;
l++ ;
}
}
return true ;
std::unique_ptr<treenode>andstd::vector<std::unique_ptr<treenode>>to avoid any leaks.rightorleft[l]=trueis like those annoying people who'll answer "yes" when you ask "coffee or tea?". Useenum Direction { left, right };or something like that.