Modifying elements of a binary tree c++

0

I have a problem concerning modifying the elements of a binary tree. This is the error I get: Access violation reading location 0x00000018. I think I'm accessing a null pointer but I don't know how to solve the problem.

This is the code that I used:

void modifyStatus(nod* root)
{

if (root->info.st == done)
    root->info.st = reachedDest;
    modifyStatus(root->st);
    modifySatus(root->dr);
}

I must specify that "done" and "reachedDest" are the elements of an enum.

c++
binary-tree
asked on Stack Overflow Jun 23, 2015 by emx908 • edited Jun 23, 2015 by emx908

1 Answer

1

I think I'm accessing a null pointer but I don't know how to solve the problem.

Check the pointer for NULL before accessing it:

void modifyStatus(nod* root) {
    if (!root) {
        return;
    }
    ...
}

Note that calls that look like this modifySatus(root->st); look like C, not like C++. In situations when you have control over nod class, you should consider making modifySatus a member function:

root->modifyStatus();
answered on Stack Overflow Jun 23, 2015 by dasblinkenlight

User contributions licensed under CC BY-SA 3.0