无法 return 退出递归

Not able to return out of recursion

我有以下一段代码。它旨在以深度优先的方式遍历[附截图]树结构。

如您所见,我对绿色突出显示的条目很感兴趣 -> 具有此树结构的 Class( DatasetType ) 节点。此树结构受客户添加新节点的影响。所以,我必须遍历树结构来找到我感兴趣的节点。我制定了以下代码。但是我可以看到它标识了我感兴趣的那个节点。

然而,它并不止于此。它正在进入下一个兄弟,即 Has Class( EPMJob )。我希望我的处理停止。我很确定我的退货方式遗漏了一些东西。但无法准确定位。

欢迎任何意见。

tag_t findHasTypeDatasetNodeInAMTree( tag_t amTreeNode )
{
    CharPointer nodeName;
    Response stat = askRuleName( amTreeNode, &nodeName );

    CharPointer nodeArgument;
    stat = askRuleArg( amTreeNode, &nodeArgument );

    if( tc_strcmp( nodeName.getString(), "Has Class" ) == 0 && tc_strcmp( nodeArgument.getString(), "DatasetType" ) == 0 )
    {
        return amTreeNode;
    }

    int numChildNodes = 0;
    TagPointer childNodes;
    stat = askChildren( amTreeNode, &numChildNodes, &childNodes );

    if( numChildNodes == 0 )
    {
        return NULLTAG;
    }

    // The following is the piece that needs attention. 
    // Do not want to NULL check here though
    for( int inx = 0; inx < numChildNodes; ++inx )
    {
        findHasTypeDatasetNodeInAMTree( childNodes[inx] );
    }

    return NULLTAG;
}

我不确定这是在做什么:

for( int inx = 0; inx < numChildNodes; ++inx )
{
    findHasTypeDatasetNodeInAMTree( childNodes[inx] );
}

但我很确定它不会在你找到东西时停止,所以结果总是 NULLTAG。怎么样:

for( int inx = 0; inx < numChildNodes; ++inx )
{
    auto result = findHasTypeDatasetNodeInAMTree( childNodes[inx] );
    if( result != NULLTAG )
        return result;
}