Visual studio 2017 c++ if and else statements are not executed.

Asked 2 years ago, Updated 2 years ago, 53 views

When you are coding a red black tree and debug granpa!= nullptr even though it is true, the entire phrase is skipped. I stopped it in debugging mode and checked it by pressing f11, but I only ran the line with if and else, and ignored all the codes inside. What's wrong with this?

if (granpa != nullptr) {
        if (granpa->left == parent) {
            granpa->left == n;
        }
        else if (granpa->right == parent) {
            granpa->right == n;
        }
    }
    else {
        root = n;
    }

c++ if문

2022-09-21 18:38

1 Answers

If you look at the code given... "granpa!=nullptr is correct, but granpa->left and granpa->right may not be parent. (I don't know what it is.) It's very normal to do nothing at this time.

Make a else block under else if and do something.


2022-09-21 18:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.