Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help implementing the MyHashTable.h file. Below is show what and where I need the functions help implemented at. Please do not modify MyHash.cpp
I need help implementing the MyHashTable.h file. Below is show what and where I need the functions help implemented at. Please do not modify MyHash.cpp in anyway
MyHash.cpp:
#include#include #include "MyHashTable.h" using namespace std; void menu(); // print out the menu int main() { string value; string key; int choice; MyHashTable table; do{ menu(); cout << "Enter your choice: "; cin >> choice; switch(choice){ case 1: cout << "Enter an (Key, Value) pair that you will add to table "; cout << "Separate by white space: "; cin >> key; cin >> value; table.insert(key, value); cout << "(" << key << ", " << value << ") entered "; break; case 2: cout << "Enter a key that you will remvoe from table: "; cin >> key; value = table.remove(key); if(value.empty()) cout << "Remove successfully. The removed value is " << value; else cout << "No such key in table"; break; case 3: cout << "Enter the key that you want to search for: "; cin >> key; value = table.get(key); if(value.empty()) cout << "No such data in table "; else cout << "The corresponding value is: " << value << endl; break; case 4: if(table.isEmpty()) cout << "table is empty "; else printTable(table); break; case 5: cout << "Make sure you run enough test before you turn it in "; break; default: cout << "Wrong option. Please choose from menu "; break; } }while(choice != 5); } void menu(){ cout << "********************************" << endl; cout << "* MENU *" << endl; cout << "* 1. Add a (key, value) pair *" << endl; cout << "* 2. Remove a value by its key *" << endl; cout << "* 3. Search a value by its key *" << endl; cout << "* 4. Print out table *" << endl; cout << "* 5. Quit *" << endl; cout << "********************************" << endl; }
MyHashTable.h:
#includeusing namespace std; #ifndef MyHashTable_h #define MyHashTable_h template struct MyHashEntry{ K key; V value; MyHashEntry* next; }; template class MyHashTable{ public: template friend void printTable(MyHashTable table); MyHashTable(int table_size); // table_size is the number of buckets MyHashTable(); // default table size is 10 int size() const; // return how many elements in table V get(K key) const; // return the element with given key bool insert(K key, V value); //insert (key, value) node to table V remove(K key); // remove and return the value with the key bool isEmpty() const; // return true if the table is empty private: MyHashEntry ** table; int count; // how many elements in table int numOfBuckets; }; // you implement your friend function and member functions here #endif /* MyHashTable_h */
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started