c++ - Function parameter - pointer or reference to a pointer? -
void deletechildren(bstnode *node) { // recurse left down tree... if(node->hasleftchild()) deletechildren(node->getleftchild()); // recurse right down tree... if(node->hasrightchild()) deletechildren(node->getrightchild()); // clean data @ node. node->cleardata(); // assume deletes internal data // free memory used node itself. delete node; } // call external code. deletechildren(rootnode);
this function deleting bst recursively.
i got question first line, bstnode *node
, should modify bstnode *& node
?
no, pointers passed value, you're in essence "copying" pointer when pass parameter. pass reference when want callee modify parameter in caller.
Comments
Post a Comment