programming-examples/c++/Others/TestQuadraticProbing.cpp - Test program for quadratic probing hash tables.cpp
2019-11-15 12:59:38 +01:00

35 lines
996 B
C++

TestQuadraticProbing.cpp - Test program for quadratic probing hash tables
#include <iostream.h>
#include "QuadraticProbing.h"
// Simple main
int main( )
{
int ITEM_NOT_FOUND = -9999;
HashTable<int> H( ITEM_NOT_FOUND );
const int NUMS = 4000;
const int GAP = 37;
int i;
cout << "Checking... (no more output means success)" << endl;
for( i = GAP; i != 0; i = ( i + GAP ) % NUMS )
H.insert( i );
for( i = 1; i < NUMS; i += 2 )
H.remove( i );
for( i = 2; i < NUMS; i +=2 )
if( H.find( i ) != i )
cout << "Find fails " << i << endl;
for( i = 1; i < NUMS; i += 2 )
{
if( H.find( i ) != ITEM_NOT_FOUND )
cout << "OOPS!!! " << i << endl;
}
return 0;
}