Hi experts,
I'm currently working on an assignment for my Data Structure course. I'm using C++ to develop a Phone Directory System. The System will be able to store name and phone number in a text file. The operations such as delete, insert and search must follow the AVL method. The "insert" is working but the "delete" and "search" are not. Below are the codes for search that i'm using. I could'nt find the workable codes for delete. Please help. Thank you for your kind attention and help.
void AVL::search(str ing x) // This is for search
{
search1(root,x) ;
}
/*void AVL::search1(AV LNODE *temp,string x)
{
AVLNODE *ptr,*save;
int flag;
if(temp==NULL)
{
cout<<"\nthe tree is empty";
return;
}
if(temp->data==x)
{
cout<<"\nthe item is root and is found";
par=NULL;
loc=temp;
par->left=NULL;
par->right=NULL;
return; }
if( x < temp->data)
{
ptr=temp->left;
save=temp;
}
else
{
ptr=temp->right;
save=temp;
}
while(ptr!=NULL )
{
if(x==ptr->data)
{
flag=1;
cout<<"\nitemfo und";
loc=ptr;
par=save;
}
if(x<ptr->data)
ptr=ptr->left;
else
ptr=ptr->right;
}
if(flag!=1)
{
cout<<"item is there in tree";
loc=NULL;
par=NULL;
cout<<loc;
cout<<par;
}
}
void AVL::search1(AV LNODE *temp,string x)
{
temp=root;
int Flag=0;
if(temp==NULL)
{
cout<<"\nthe tree is empty";
return;
}
// tmp=root;
while(temp!=NUL L)
{
if(x<temp->data)
temp=temp->left;
else if(x>temp->data)
temp=temp->right;
else
{
cout<<"Record Found! Name-->"<<temp->data<<" Phone-->"<<temp->phone<<endl;
Flag = 1;
return;
// return tmp->data;
}
}
if (Flag==0)
{cout<<"Record Not Found!"<<endl;}
//return NULL;
}
I'm currently working on an assignment for my Data Structure course. I'm using C++ to develop a Phone Directory System. The System will be able to store name and phone number in a text file. The operations such as delete, insert and search must follow the AVL method. The "insert" is working but the "delete" and "search" are not. Below are the codes for search that i'm using. I could'nt find the workable codes for delete. Please help. Thank you for your kind attention and help.
void AVL::search(str ing x) // This is for search
{
search1(root,x) ;
}
/*void AVL::search1(AV LNODE *temp,string x)
{
AVLNODE *ptr,*save;
int flag;
if(temp==NULL)
{
cout<<"\nthe tree is empty";
return;
}
if(temp->data==x)
{
cout<<"\nthe item is root and is found";
par=NULL;
loc=temp;
par->left=NULL;
par->right=NULL;
return; }
if( x < temp->data)
{
ptr=temp->left;
save=temp;
}
else
{
ptr=temp->right;
save=temp;
}
while(ptr!=NULL )
{
if(x==ptr->data)
{
flag=1;
cout<<"\nitemfo und";
loc=ptr;
par=save;
}
if(x<ptr->data)
ptr=ptr->left;
else
ptr=ptr->right;
}
if(flag!=1)
{
cout<<"item is there in tree";
loc=NULL;
par=NULL;
cout<<loc;
cout<<par;
}
}
void AVL::search1(AV LNODE *temp,string x)
{
temp=root;
int Flag=0;
if(temp==NULL)
{
cout<<"\nthe tree is empty";
return;
}
// tmp=root;
while(temp!=NUL L)
{
if(x<temp->data)
temp=temp->left;
else if(x>temp->data)
temp=temp->right;
else
{
cout<<"Record Found! Name-->"<<temp->data<<" Phone-->"<<temp->phone<<endl;
Flag = 1;
return;
// return tmp->data;
}
}
if (Flag==0)
{cout<<"Record Not Found!"<<endl;}
//return NULL;
}