在bst中搜索密钥

searching for a key in a bst

本文关键字:密钥 搜索 bst      更新时间:2023-10-16

编译器告诉我断言失败,尽管我在链接节点数组中至少有2个项。如何修复此bool-contains函数?是的,我尝试了多种方法,但仍然会出现同样的错误。

请记住,数组的不同索引中有2个项。但下面没有显示。

这是contain函数:

bool Map::contains(string key){
bool idk = false;
if(elementsStoredCount != 0){
    int idk = hashFunc(key); //the hashFunc computes using modulo
    if(array[found] != nullptr){
        idk = false;
    }
    else{
        found = true;
    }
}

return found;
}

当我在main.cpp中测试时,第二行由于某种原因失败了。

assert(as.contains("1")==true);

根据其他一些注释和阅读代码,我认为您的问题是int hashFunc(string key)函数返回的索引不正确,超出了array[]的范围。

您是否调试/测试了hashFunc()函数以确保数据正确?如果实现正确,并且您仍然面临错误,那么我接下来会看看您的表数据/插入函数。