我不知道为什么这段代码没有跳出 while 循环:
int table_size = 953;
store hash_table[953];
for(int i = 0; i < table_size; i++)
hash_table[i].count = 0;
//bunch of stuff to get hash value here
while(hash_table[hashNum].data != pString || hash_table[hashNum].count != 0){
hashNum++;
if(hashNum > table_size)
hashNum = 0;
cout << hash_table[hashNum].count;
// to check the value of the count in the array, it IS 0, thus should have broken the loop
}
最佳答案
你的意思可能是:
while(hash_table[hashNum].data != pString && hash_table[hashNum].count != 0)
在您的代码中,如果任一情况为真,循环将继续,hash_table[hashNum].count == 0
不足以使子句为假。
关于c++ - 似乎无法在碰撞、散列时打破 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5959296/