for some reason my nodes don't seem to be deleting. it looks as though it traverses to the end ok but after the node is "deleted" it still has the data in it. i've also tried
free(bNode)
and bNode = NULL
instead of delete bNode
but they all give the same result.
The cout
and display functions were just put in when I was trying to debug. I just don't understand why its not working, i hope i'm not missing something simple.
struct
Book{
char title [50];
char url [75];
Book *left;
Book *right;
};
void deleteAllBooks (Book *bNode){
if(bNode==NULL) return;
if(bNode->left !=NULL){
cout << endl << "deleting left" << endl;
deleteAllBooks(bNode->left);
}
if(bNode->right !=NULL){
cout << endl << "deleting right" << endl;
deleteAllBooks(bNode->right);
}
cout << endl << "deleting node " << bNode->title << endl;
delete bNode;
displayBookTree(bNode);
}
void displayBookTree(Book *bNode){
if(bNode==NULL){
cout << "No books" << endl;
return;
}
if(bNode->left !=NULL){
displayBookTree(bNode->left);
}
if(bNode->right !=NULL){
displayBookTree(bNode->right);
}
cout <<"Title: " << bNode->title << endl;
cout <<"URL: " << bNode->url <<endl;
}