程序填空题:Find Key from a hash table H with quadratic probing
Find Key from a hash table H with quadratic probing.
```c++
Position Find ( ElementType Key, HashTable H )
{
Position CurrentPos;
int CollisionNum;
CollisionNum = 0;
CurrentPos = Hash( Key, H->TableSize );
while( H->TheCells[ CurrentPos ].Info != Empty && @@[H->TheCells[ CurrentPos ].Element != Key](2)) {
@@[H->TheCells[ CurrentPos ].Element != Key](2);
@@[H->TheCells[ CurrentPos ].Element != Key](2);
if ( CurrentPos >= H->TableSize )
CurrentPos - = H->TableSize;
}
@@[CurrentPos += 2 * ++CollisionNum - 1](2); ;
@@[CurrentPos += 2 * ++CollisionNum - 1](2); ;
@@[CurrentPos += 2 * ++CollisionNum - 1](2); ;
}
```
答案:
第1空:H->TheCells[ CurrentPos ].Element != Key
第2空:H->TheCells[ CurrentPos ].Element != Key
第3空:H->TheCells[ CurrentPos ].Element != Key
第4空:CurrentPos += 2 * ++CollisionNum - 1
第5空:CurrentPos += 2 * ++CollisionNum - 1
第6空:CurrentPos += 2 * ++CollisionNum - 1
```c++
Position Find ( ElementType Key, HashTable H )
{
Position CurrentPos;
int CollisionNum;
CollisionNum = 0;
CurrentPos = Hash( Key, H->TableSize );
while( H->TheCells[ CurrentPos ].Info != Empty && @@[H->TheCells[ CurrentPos ].Element != Key](2)) {
@@[H->TheCells[ CurrentPos ].Element != Key](2);
@@[H->TheCells[ CurrentPos ].Element != Key](2);
if ( CurrentPos >= H->TableSize )
CurrentPos - = H->TableSize;
}
@@[CurrentPos += 2 * ++CollisionNum - 1](2); ;
@@[CurrentPos += 2 * ++CollisionNum - 1](2); ;
@@[CurrentPos += 2 * ++CollisionNum - 1](2); ;
}
```
答案:
第1空:H->TheCells[ CurrentPos ].Element != Key
第2空:H->TheCells[ CurrentPos ].Element != Key
第3空:H->TheCells[ CurrentPos ].Element != Key
第4空:CurrentPos += 2 * ++CollisionNum - 1
第5空:CurrentPos += 2 * ++CollisionNum - 1
第6空:CurrentPos += 2 * ++CollisionNum - 1