Red-Black-Tree icon indicating copy to clipboard operation
Red-Black-Tree copied to clipboard

Not working insert / delete case

Open ALEXks opened this issue 5 years ago • 5 comments

In this case I get an error:

for (int z = 0; z < 30000; ++z)
    {
        printf(" Z = %d\n", z);
        if (z == 699)
            printf("");
        data = rand() % 5000 + 220;
        rbTree1.insertValue(data);
        q.push(data);
        rbTree1.preorder();

        if (q.size() >= 15)
        {
            rbTree1.deleteValue(q.front());            
            q.pop();
        }
    }

if Z equal 699 deletion fails with segfoult in the flowing

int RBTree::getColor(Node*& node) 
{
    if (node == NULL)
        return BLACK;

    return node->color;
}

ALEXks avatar Jul 12 '19 07:07 ALEXks

Did you by any chance find the root cause ? :)

On Fri, 12 Jul 2019 at 09:00, Alexander [email protected] wrote:

In this case I get an error:

for (int z = 0; z < 30000; ++z) { printf(" Z = %d\n", z); if (z == 699) printf(""); data = rand() % 5000 + 220; rbTree1.insertValue(data); q.push(data); rbTree1.preorder();

    if (q.size() >= 15)
    {
        rbTree1.deleteValue(q.front());
        q.pop();
    }
}

if Z equal 699 deletion fails with segfoult in the flowing

int RBTree::getColor(Node*& node) { if (node == NULL) return BLACK;

return node->color;

}

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/anandarao/Red-Black-Tree/issues/1?email_source=notifications&email_token=ACZWUSSASVNUZPWD6DXKPQTP7AT2TA5CNFSM4ICDGTO2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G6ZXQXQ, or mute the thread https://github.com/notifications/unsubscribe-auth/ACZWUSQQNZOUP2SL32J4KY3P7AT2TANCNFSM4ICDGTOQ .

-- Thanks and Regards. Ananda Rao H

anandarao avatar Jul 12 '19 08:07 anandarao

Did you by any chance find the root cause ? :) On Fri, 12 Jul 2019 at 09:00, Alexander @.**> wrote: In this case I get an error: for (int z = 0; z < 30000; ++z) { printf(" Z = %d\n", z); if (z == 699) printf(""); data = rand() % 5000 + 220; rbTree1.insertValue(data); q.push(data); rbTree1.preorder(); if (q.size() >= 15) { rbTree1.deleteValue(q.front()); q.pop(); } } if Z equal 699 deletion fails with segfoult in the flowing int RBTree::getColor(Node& node) { if (node == NULL) return BLACK; return node->color; } — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#1?email_source=notifications&email_token=ACZWUSSASVNUZPWD6DXKPQTP7AT2TA5CNFSM4ICDGTO2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G6ZXQXQ>, or mute the thread https://github.com/notifications/unsubscribe-auth/ACZWUSQQNZOUP2SL32J4KY3P7AT2TANCNFSM4ICDGTOQ . -- Thanks and Regards. Ananda Rao H

Yes, and I think the main reason is appearance of DOUBLE_BLACK color in the nodes. You can easily repeat this case in Windows system (my be in Linux too) because RAND function creates the same sequence.

ALEXks avatar Jul 12 '19 08:07 ALEXks

Can you send a pull request if you have a fix ? :) I've lost touch of this repo.

anandarao avatar Jul 14 '19 21:07 anandarao

Sorry, I do not want to look for an error =)

ALEXks avatar Jul 15 '19 13:07 ALEXks

I am fixed it.

JohnnyP0T avatar Jan 15 '21 08:01 JohnnyP0T