浙大版《数据结构(第2版)》题目集
习题5.10 线性探测法的查找函数 (20 分)
把两个if条件写开就答案正确
Position Find( HashTable H, ElementType Key )
{
Position ind;
int count = 0;
//循环表长长度
while(count < H->TableSize){
//获取Key第一次在的位置
ind = Hash(Key +count,H->TableSize);
if(H->Cells[ind].Info == Legitimate){ //就是这里
if(H->Cells[ind].Data == Key){//还有这里
return ind;
}
}else{
return ind;
}
count++;
}
return ERROR;
}
把if的两个条件写在一起,结果就是部分正确
Position Find( HashTable H, ElementType Key )
{
Position ind;
int count = 0;
//循环表长长度
while(count < H->TableSize){
//获取Key第一次在的位置
ind = Hash(Key +count,H->TableSize);
if(H->Cells[ind].Info == Legitimate && H->Cells[ind].Data == Key){//就是这里
return ind;
}else{
return ind;
}
count++;
}
return ERROR;
}