Header file:
#include <iostream>using namespace Std;template<class hash_type>class hash_set{private:hash_type array[ 100000];int Hash_fun (hash_type original);p ublic:hash_set ();//constructor void Insert (Hash_type value);//Insert an element void erase ( Hash_type target);//delete an element bool contain (hash_type query);//Determine whether an element is in the collection};
class function implementations:
#include "hash_set.h" template<class hash_type> #define MAX_LENGTH 100000int Hash_set
To test the main function:#include <iostream> #include "hash_set.cpp" int main () {hash_set<int> Hs;while (True) {cout << "Begin Test:\ninput 1 to Insert;2 to find; 3 to delete\n "; Int. Flag;int value;cin >> flag;switch (flag) {case 1:cout << ' input the value to insert:\n '; CIN >> Value;hs.insert (value); Break;case 2:cout << "input the value to find:\n"; Cin >> Value;if (hs.contain (value)) cout << "yes\n"; else cout << "no\n"; break;case 3:cout << "input the value to delete\n"; Cin >> Valu E;hs.erase (value); Break;default:cout << "Input error.\n"; break;}} return 0;}
C + + Implementation Hash_set