0
我想爲類編寫一個哈希表,我似乎無法得到這個while循環工作。你們看到有什麼問題嗎? 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;
}
請舉例說明使用情況。你怎麼調用這個函數?你爲num,table_size傳遞了什麼值? – 2011-05-13 22:36:03