Deleting key and data in RBtree

I am working on RBTree deletion part for one of my assignment using Cormen as reference book. User will pass the key and data. The program should be able to search the whole tree for the given key-data pair and delete all their occurrences from the tree.

ex:<br>
Before :

01 01
01 01
02 02
03 03
01 01
delete 01 01<br>
After :

02 02
03 03

I wrote the following piece of code :-<br>

void rbDelete(const string& key, const string& data)
{
Node* tmp=rbTreeSearch(root,key);
bool found=false;
Node *successor,*predecessor;

while(*tmp->value==data)
{

successor=rbTreeSuccessor(tmp);
predecessor=rbTreePredecessor(tmp);

if(tmp!=nil && *tmp->value==data)
{
rbDelete(tmp);
tmp=rbTreeSearch(root,key);
}
else if (*successor->key==*tmp->key && *successor->value==*tmp->value)

rbDelete(successor);

}

if(found!=true)
{
return;
}
}

But I am getting segmentation fault while executing it.

Program should silently ignore errors (such as if a user tries to delete a node that doesn't exist). I am using successor and predecessor and to find additional matches. Segmentation fault also needs to be taken care over here.

This code piece is not working. Not getting how to accomplish my task from it. Definitely there could be better ways to achieve the task but I am not getting the point.Please help. Thanks in advance
Topic archived. No new replies allowed.