小编Rom*_*pez的帖子

Bool方法返回错误的值

bool contains(string)为链表散列表创建了一个方法,用于检查值是否在散列中.我使用辅助函数来递归,但是当辅助函数返回时false,bool contains(string)仍然返回true.我通过调试器运行它,我可以清楚地看到它返回false,我不知道为什么.

这是当前搜索的节点:

"laccoliths"->"morbiferous"->"oculi"->"unscabbarded"

我正在寻找的价值是"typung".

这是代码:

bool contains_h(string x, node * p) //helper method
{
    if (p == NULL)
        return false;
    else if (x == p->data)
        return true;
    else
        contains_h(x, p->next);
}
Run Code Online (Sandbox Code Playgroud)

bool contains(string word) { return contains_h(word, head); }

c++ boolean-logic boolean return-value boolean-expression

4
推荐指数
1
解决办法
394
查看次数