emx908
emx908

Reputation: 11

Modifying elements of a binary tree c++

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.

Upvotes: 0

Views: 83

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726589

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();

Upvotes: 1

Related Questions