Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

rewrite my program , Not generic; single letter ids (not readable); entries are arrays, not lists; wrong method names; does not throw exception; key_comp() not

rewrite my program, Not generic; single letter ids (not readable); entries are arrays, not lists; wrong method names; does not throw exception; key_comp() not implemented; Missing operators =, ==. (visual studio 2019 compiler) this compiler is required by my professor and I cannot use a different compiler unfortunately

image text in transcribed

#include

const int T_S = 200; using namespace std;

struct HashTableEntry { string v; int k; HashTableEntry* n; HashTableEntry* p; HashTableEntry(int k, string v) { this->k = k; this->v = v; this->n = NULL; } };

class HashMapTable { public: HashTableEntry** ht, ** top; HashMapTable() { ht = new HashTableEntry * [T_S]; for (int i = 0; i n; } if (en == NULL) { en = new HashTableEntry(k, v); if (p == NULL) { ht[hash_v] = en; } else { p->n = en; } } else { en->v = v; } }

void Remove(int k) { int hash_v = HashFunc(k); HashTableEntry* en = ht[hash_v]; HashTableEntry* p = NULL; if (en == NULL || en->k != k) { cout n != NULL) { p = en; en = en->n; } if (p != NULL) { p->n = en->n; } delete en; cout

void SearchKey(int k) { int hash_v = HashFunc(k); bool flag = false; HashTableEntry* en = ht[hash_v]; if (en != NULL) { while (en != NULL) { if (en->k == k) { flag = true; } if (flag) { cout v n; } } if (!flag) cout

void At(int k) { int hash_v, key = 0; bool flag = false; for (int i = 0; i k == k) { flag = true; key = i; } en = en->n; } } } if (flag) { cout

void CountAtKey(int k) { int count = 0; int hash_v = HashFunc(k); HashTableEntry* en = ht[hash_v]; if (en != NULL) { while (en != NULL) { count++; en = en->n; } } if (count == 0) { cout

}

void Erase(int k) { int hash_v = HashFunc(k); bool flag = false; HashTableEntry* en = ht[hash_v]; if (en != NULL) { en = NULL; } }

void Key_comp() { }

void Size() { int count = 0, hash_v; for (int i = 0; i n; } }

} cout

~HashMapTable() { delete[] ht; } };

image text in transcribed

Write a class template for a map with a fixed type for the keys - string, and a template type parameter for the values. Use open hashing (chaining) with an array or vector of pointers to STL linked lists. Provide the following public member functions: . Constructor Destructor Copy constructor Assignment operator Operator == Function size that returns the number of key-value pairs in the map Function count that returns the number of elements with a specific key Function insert that inserts a key-value pair into the map Function at that returns a reference to the mapped value of the element identified with a specific key k. If k does not match the key of any element in the map, the function should throw an out of ange exception. Function erase that removes a key-value pair identified with a specific key k. If k does not match the key of any element in the map, the function should throw an out of range exception Function key..come that returns a key comparison object, a function object comparing keys and returning true if the first argument (key) for comparison is less than the second and false otherwise Hint: First implement a class for values of some fixed data type, for example integer or string, and then convert it to a class template. It makes sense to submit both the non-template and the template versions. case 5: int main() //test program { HashMap Table hash; int k; string v; int c; while (1) { cout > C; switch (c) { case 1: cout > V; cout > k; hash. Insert(k, v); break; case 2: cout > k; hash. SearchKey(k); break; case 3: cout > K; hash. Remove(k); break; case 4: cout > k; hash.CountAtKey(K); break; hash.Size(); break; case 6: cout > k; hash.At(k); break; case 7: cout >k; hash. Erase(k); break; case 8: exit(1); default: coul > C; switch (c) { case 1: cout > V; cout > k; hash. Insert(k, v); break; case 2: cout > k; hash. SearchKey(k); break; case 3: cout > K; hash. Remove(k); break; case 4: cout > k; hash.CountAtKey(K); break; hash.Size(); break; case 6: cout > k; hash.At(k); break; case 7: cout >k; hash. Erase(k); break; case 8: exit(1); default: coul

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions