C++ 在哈希表中搜索帮助!

C++ 在哈希表中搜索帮助!,c++,search,hash,g++,C++,Search,Hash,G++,我试图为类编写一个哈希表,但在循环工作时,我似乎无法得到这个。你们觉得有什么问题吗?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_si

我试图为类编写一个哈希表,但在循环工作时,我似乎无法得到这个。你们觉得有什么问题吗?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;
}
void搜索(存储t[],字符串s,int num,int table_size)
{
int temp=num;
bool exit=false;
while(t[temp].data!=s&&!exit){
temp++;
如果(温度==表大小){
不能试着改变

 int temp = num;


你的while循环看起来不错

但是你确定下面这句话吗

if(t[num].data == s)
    cout<<"("<<s<<")"<<" appears "<<t[num].count<<" times."<<endl;
if(t[num].data==s)

请给出一个用法示例。您如何调用此函数?您为num、table\u size传递了哪些值?
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;