繁体   English   中英

当 i=1 和 v=4 的外部 if 为假时,如何执行内部 if 条件

[英]How inner if condition is executed evebn when the outer if is false for i=1 and v=4

1 当 i=1 和 v=4 的外部 if 条件为假时,内部 if 条件如何工作。

if (i == V) {
        // if coloring is safe
        if (isSafe(graph, color)) {
            // Print the solution
            printSolution(color);
            return true;
        }
        return false;
    }

请参阅此程序以获取完整代码

https://ide.geeksforgeeks.org/AfK9JFN2aD

2 有人可以解释一下代码是如何工作的吗?如何为每个节点分配一种新颜色。 https://ide.geeksforgeeks.org/AfK9JFN2aD

if (i == V)
{
    // if coloring is safe
    if (isSafe(graph, color))
    {
        // Print the solution
        printSolution(color);
        return true;
    }
    return false;
}

这相当于:

if (i == V) goto FIRST_IF_START;
else        goto FIRST_IF_END;

FIRST_IF_START:
{
    // if coloring is safe
    if (isSafe(graph, color)) goto SECOND_IF_START;
    else                      goto SECOND_IF_END;

    SECOND_IF_START:
    {
        // Print the solution
        printSolution(color);
        return true;
    }
    SECOND_IF_END:
    return false;
}
FIRST_IF_END:

我希望这能更好地说明if的工作原理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM