在bst中搜索密钥
searching for a key in a bst
编译器告诉我断言失败,尽管我在链接节点数组中至少有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()
函数以确保数据正确?如果实现正确,并且您仍然面临错误,那么我接下来会看看您的表数据/插入函数。
相关文章:
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 允许从 std::map 的密钥窃取资源?
- TMap::Emplace() 在应用现有密钥时会覆盖吗?
- 在没有密钥的情况下读取密文的剩余噪声预算
- 如何修复无效的API密钥,IP或操作权限错误?
- 所有可能的链接生成器与64位密钥
- 如何在unordered_map中更改密钥?
- 获取当前密钥状态?
- curl_easy_perform() 失败:SSL 对等证书或 SSH 远程密钥不正常
- 将密钥发送到非前台的游戏窗口
- 有哪些方法可以对基于 256 位密钥的矩阵进行加扰?
- 如何在精灵表上的两个不同部分之间来回切换,同时用户仍使用 SFML 持有密钥
- 如何将CNG密钥转换为OpenSSL EVP_PKEY(反之亦然)?
- 运行密钥密码解密知道密钥?
- std::unordered_map 运算符 [] 是否对非现有密钥进行零初始化?
- 封装 std::map 以允许迭代,但没有直接密钥访问?
- 是否可以显示需要线性搜索的时间才能找到您在程序中找到的密钥
- 在不使用密钥的情况下有效地搜索哈希表
- 在bst中搜索密钥
- 在一对多映射中搜索一个密钥