在哈希表中搜索帮助
Searching in a hash table HELP!
我正在尝试为类编写一个哈希表,但在循环工作时似乎无法得到它。 你们觉得有什么问题吗?while 循环过早结束,我认为我的 while 循环条件有问题?
void search(store t[], string s, int num, int table_size)
{
int temp = num;
bool exit = false;
while(t[temp].data != s && !exit){
temp++;
if (temp == table_size){
cout<<"reached 0 inside while loop"<<endl;
temp = 0;
}
if (temp == num){
cout<<"test search loop"<<endl; //I can't seem to get into here.
exit = true;
}
}
if(t[num].data == s)
cout<<"("<<s<<")"<<" appears "<<t[num].count<<" times."<<endl;
else
cout<<"your string is not in my table"<<endl;
}
你的while循环似乎还可以,
但是您确定以下行吗?
if(t[num].data == s)
cout<<"("<<s<<")"<<" appears "<<t[num].count<<" times."<<endl;
不应该是以下的吗?
if(t[temp].data == s)
cout<<"("<<s<<")"<<" appears "<<t[temp].count<<" times."<<endl;
因为很明显,您正在运行整个表,直到循环完成或直到找到好的 [ 即:while( t[temp].data != s ...) ]。所以我猜你正在寻找好的临时索引,但你没有在循环后使用它。
尝试更改
int temp = num;
自
int temp = 0;
相关文章:
- 有根的二进制搜索树.保留与其父级的链接
- 需要帮助设置在C++中使用的Potrace
- 在指针的帮助下,文本文件中单词的频率
- 在C++中搜索嵌套多映射值
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 二进制搜索树叶数问题
- 为什么二进制搜索在我的测试中不起作用
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何在Qbutton的帮助下更改Q对话框的宽度
- 正在尝试重载二进制搜索树分配运算符
- 需要帮助将结构数组传递给函数
- c++binary_search函数排序数组(流行名称搜索)出现问题
- 需要帮助在填充了用户输入的向量中搜索最小值
- 我需要帮助创建一个可以搜索数组的函数
- 需要二叉树程序的帮助(不是二叉搜索树)
- 需要帮助搜索功能为我的电影数据库c++
- 需要帮助从结构向量中搜索元素
- 在哈希表中搜索帮助
- 帮助实现在结构体数组中查找名称的二进制搜索
- 在DLL搜索路径中添加路径以帮助执行依赖于DLL的EXE