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

Popular posts from this blog

jQuery clickable div with working mailto link inside -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -