Question

I was just dealing with AVL trees, insert, delete and other methods, so right now I am having a problem with my left rotation, when the node is not the root ( aka the node's parent is not equal to zero). So, a part of my method, actually the right beginning of it goes like this:

void LR (Node* &c)
{
    if (c->_parent != 0)
    {
        if ( c == c->_parent->_left)
        {
            c->_parent->_left = c->_right;
        }
        else
        c->_parent->_right = c->_right;
        c->_right->_parent = c->_parent;
    }
etc. etc.

So, when I have a node c, that has key 389, parent non zero and right child non zero too, with a key equal to 390, my code dumps and it says that right after this instr.:

    c->_parent->_left = c->_right;

my right child, c->_right becomes null :/ I don't get it. Anybody?

Était-ce utile?

La solution 2

My parameter of the LR function was a reference, so that is why I lost the adreses :D c->_parent->_left got the same as c :D so I basically did this : c = c->_right :D It works now that I have corrected it.

Autres conseils

If using a debugger c is not zero AND c->right is not zero at the point the program gets a segmentation fault then check that the program you are debugging has compiled correctly.

Watch the pertinent variables for a change in value and step through until the variable becomes in valid.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top