// https://www.tutorialspoint.com/cplusplus-program-to-implement-hash-tables #include #include #include #include using namespace std; const int T_S = 200; class HashTableEntry { public: int k; int v; HashTableEntry(int k, int v) { this->k= k; this->v = v; } }; class HashMapTable { private: HashTableEntry **t; public: HashMapTable() { t = new HashTableEntry * [T_S]; for (int i = 0; i< T_S; i++) { t[i] = NULL; } } int HashFunc(int k) { return k % T_S; } void Insert(int k, int v) { int h = HashFunc(k); while (t[h] != NULL && t[h]->k != k) { h = HashFunc(h + 1); } if (t[h] != NULL) delete t[h]; t[h] = new HashTableEntry(k, v); } int SearchKey(int k) { int h = HashFunc(k); while (t[h] != NULL && t[h]->k != k) { h = HashFunc(h + 1); } if (t[h] == NULL) return -1; else return t[h]->v; } void Remove(int k) { int h = HashFunc(k); while (t[h] != NULL) { if (t[h]->k == k) break; h = HashFunc(h + 1); } if (t[h] == NULL) { cout<<"No Element found at key "<>c; switch(c) { case 1: cout<<"Enter element to be inserted: "; cin>>v; cout<<"Enter key at which element to be inserted: "; cin>>k; hash.Insert(k, v); break; case 2: cout<<"Enter key of the element to be searched: "; cin>>k; if (hash.SearchKey(k) == -1) { cout<<"No element found at key "<>k; hash.Remove(k); break; case 4: exit(1); default: cout<<"\nEnter correct option\n"; } } return 0; }