c++ - Delete a node from a binary tree avoiding memory leaks -
c++ - Delete a node from a binary tree avoiding memory leaks -
i want delete given node pointer binary tree, want alter pointer of 1 of children(let's left one).
if this:
node<t> *tmp = root->getleftnode(); delete root; root = tmp;
the pointer root ends not having value of left child.
if this:
root = root->getleftnode();
it works, obvious memory leak.
how can correctly delete root?
edit: tried removenode method using memory leaks approach , works (my code seems logically correct). when utilize delete in way root pointer ends having big negative number(which not valid address).
it seems reply should correct, need post little more information. trying store value of left kid in root, or root pointer node? if trying value of left child, i'd use:
root = *tmp;
c++ memory-leaks binary-tree delete-operator
Comments
Post a Comment