quick note first: the code seams to work fine and for all purposes does what its meant to, but when i list the node contents after removing the node i get some garbage, i've looked at the list code and its definately not that
heres the code -
/////////////////////////////////////////////////
//Function that removes the selected information
//from the tree
//
struct PTRnode* removeFromList(PTRnode* root, datatype &data)
{
PTRnode *tempnode; //temporary node to hold root information
PTRnode *TheSuccessor; //a pointer to the next node after the selected node
if(strcmpi(KEY, PRIM_KEY)<0)//check if key is less than prim_key
{
if(root->left!=NULL) //check if the left pointer is not equal to NULL
{
removeFromList(root->left); //call function and go left
}
}
else
{
if(strcmpi(KEY, PRIM_KEY)==0)//check if the two keys match
{
if(root->left==NULL) //check if the left pointer is equal to NULL
{
if(root->right==NULL) //check if the right pointer is equal to NULL
{
//node is an empty leaf
free(root); //free the memory used by root
root=NULL; //assign a value of NULL to root
}
else
{
//only a right pointer exists
tempnode = root; //store root contents into tempnode
root = root->right; //move contents of root->right into root
free(tempnode); //free memory of tempnode
}
}
else
{
if(root->right==NULL) //check if the right pointer is equal to NULL
{
//only a left pointer exists
tempnode = root; //store root contents into tempnode
root=root->left; //move contents of root->left into root
free(tempnode); //free memory of tempnode
}
else
{
//both left and right pointers are not equal to NULL
//call to inordertraversal function that will check the next
//node and store the contents into TheSuccessor
TheSuccessor = inOrderTraversal(root->right, data);
root->data = TheSuccessor->data; //store the information in thesuccessor
//into root
removeFromList(root->right, TheSuccessor->data); //call function and remove
//the successor of the node
}
}
}
else
{
if(strcmpi(KEY, PRIM_KEY)>0)//check if key is bigger than prim_key
{
if(root->right!=NULL) //check if the right pointer is not equal to NULL
{
removeFromList(root->right, data); //call function and go right
}
}
}
}
return root;
}
//End removeFromList function
/////////////////////////////////////////////////
//KEY is defined earlier as data.artist
//PRIM_KEY is defined as root->data.artist
/////////////////////////////////////////////////
//Function that checks the items in the tree
//in an in order traversal
//
struct PTRnode* inOrderTraversal(PTRnode* root, datatype &data)
{
if(root!=NULL) //check if root->left is not equal to NULL
{
root->left = inOrderTraversal(root->left, data); //call function and go left
root->right = inOrderTraversal(root->right, data); //call function and go right
}
return root;
}
//End inOrderTraversal function
/////////////////////////////////////////////////
//before removal of CD - pink floyd
ARTIST TITLE
~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
boney m babylon
frankie goes to hollywood welcome to the pleasuredome
klf the white room
madness complete
madonna music
pink floyd wish you were here
queen greatest hits
//after removal of CD
ARTIST TITLE
~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
boney m babylon
frankie goes to hollywood welcome to the pleasuredome
klf the white room
madness complete
madonna music
queen greatest hits
|¡@ greatest hits //whats this?????
any help will be much appreciated
thanx