Question: *** THIS CODE IS FOR INT ONLY, I NEED TO IMPLEMENT FOR STRINGS #include #include #include #include using namespace std; const int TABLE_SIZE = 128;

 *** THIS CODE IS FOR INT ONLY, I NEED TO IMPLEMENT

*** THIS CODE IS FOR INT ONLY, I NEED TO IMPLEMENT FOR STRINGS

#include

#include

#include

#include

using namespace std;

const int TABLE_SIZE = 128;

/*

* HashEntry Class Declaration

*/

class HashEntry

{

public:

int key;

int value;

HashEntry(int key, int value)

{

this->key = key;

this->value = value;

}

};

/*

* HashMap Class Declaration

*/

class HashMap

{

private:

HashEntry **table;

public:

HashMap()

{

table = new HashEntry * [TABLE_SIZE];

for (int i = 0; i

{

table[i] = NULL;

}

}

/*

* Hash Function

*/

int HashFunc(int key)

{

return key % TABLE_SIZE;

}

/*

* Insert Element at a key

*/

void Insert(int key, int value)

{

int hash = HashFunc(key);

while (table[hash] != NULL && table[hash]->key != key)

{

hash = HashFunc(hash + 1);

}

if (table[hash] != NULL)

delete table[hash];

table[hash] = new HashEntry(key, value);

}

/*

* Search Element at a key

*/

int Search(int key)

{

int hash = HashFunc(key);

while (table[hash] != NULL && table[hash]->key != key)

{

hash = HashFunc(hash + 1);

}

if (table[hash] == NULL)

return -1;

else

return table[hash]->value;

}

/*

* Remove Element at a key

*/

void Remove(int key)

{

int hash = HashFunc(key);

while (table[hash] != NULL)

{

if (table[hash]->key == key)

break;

hash = HashFunc(hash + 1);

}

if (table[hash] == NULL)

{

cout

return;

}

else

{

delete table[hash];

}

cout

}

~HashMap()

{

for (int i = 0; i

{

if (table[i] != NULL)

delete table[i];

delete[] table;

}

}

};

int main()

{

HashMap hash;

int key, value;

int choice;

while (true)

{

cout

cout

cout

cout

cout

cout

cout

cout

cin>>choice;

switch(choice)

{

case 1:

cout

cin>>value;

cout

cin>>key;

hash.Insert(key, value);

break;

case 2:

cout

cin>>key;

if (hash.Search(key) == -1)

{

cout

continue;

}

else

{

cout

cout

}

break;

case 3:

cout

cin>>key;

hash.Remove(key);

break;

case 4:

exit(1);

default:

cout

}

}

return 0;

}

Task 1: HardCode a C Hash Table that Will Accept a Key as String and Map to String Value. First Name Jane" "John" "Susan" Last Name "Smith" "Do" "Collins" "Rodgers" Jones" "Wright" "Bader" "Eric" "Mike" Create Methods to Insert: insert(key, value) insert("First", "Last") Findvalue("First")-> Method will return value Delete("First") - Method will delete key and value

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!