Ok, apparently my destructor isn't done yet and I'm not sure how to handle this. I have an n-ary tree that contains nodes that are built of data and a vector of pointers. Each pointer was initialized with new, so I need to delete them obviously. One friend said I was fine and another said no. So, can someone explain what I'm missing?
My destructor calls this function which should delete everything in that node.
void del(node* ptr)
{ for (int y = 0; y < ptr->num; y++)
{ del(ptr->children[y]); }
delete ptr;
ptr = NULL;
}
The for call just tells it only to go down the unique variables it points to, cause each node points to other nodes that contain words one letter off and I was trying to prevent losing a branch before the nodes under it were deleted. It should stop when it finds no unique values under it, thus leaving just a vector of pointers to other nodes one letter off, which are the pointers I need to delete.
Anyway, I would assume I need to add another for that deletes the pointers in the vector, but what should that look like? This is what I thought it would need but my compiler didn't like it Any help would be appreciated.
void del(node* ptr)
{ for (int y = 0; y < ptr->num; y++)
{ del(ptr->children[y]); }
for (int x = 0; x < ptr->children.size(); x++)
{ delete ptr->children[x];
ptr->children[x] = NULL; }
delete ptr;
ptr = NULL;
}