[Solved]Please Update Following C Code Simple Hash Tables Accept Key String Map String Value Pleas Q37112570
Please Update my following C++ code for Simple HashTables so it will Accept a Key as String and Map to String Value.Please explain each lines of code too;
First Name
Last Name
“Jane”
“Smith”
“John”
“Do”
“Susan”
“Collins”
“Bill”
“Rodgers”
“Eric”
“Jones”
“Bill”
“Wright”
“Mike”
“Bader”
Use Conventional Method Names Insert, Remove,Search:
insert(key, value)
insert(“First”, “Last”)
Search(“First”) → Method will return value
Remove(“First”) → Method will delete key andvalue
//my code
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;
const int TABLE_SIZE = 128;
/*
* HashEntry Class Declaration
*/
class HashEntry {
public:
int key;
int value;
HashEntry(int key, intvalue) {
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_SIZE; i++) {
table[i]= NULL; }
}
/*
* HashFunction
*/
int HashFunc(int key){
returnkey % TABLE_SIZE; }
/*
* InsertElement at a key
*/
void Insert(int key, int value) {
inthash = HashFunc(key);
while(table[hash] != NULL && table[hash]->key != key) {
hash= HashFunc(hash + 1); }
if(table[hash] != NULL)
deletetable[hash];
table[hash]= new HashEntry(key, value); }
/*
* SearchElement 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
returntable[hash]->value; }
/*
* RemoveElement 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<<“NoElement found at key “<<key<<endl;
return; }
else{
deletetable[hash]; }
cout<<“ElementDeleted”<<endl; }
~HashMap() {
for(int i = 0; i < TABLE_SIZE; i++) {
if(table[i] != NULL)
deletetable[i];
delete[]table; } }
};
/*
* Main Contains Menu
*/
int main() {
HashMap hash;
int key, value;
int choice;
while (1) {
cout<<“n———————-“<<endl;
cout<<“Operationson Hash Table”<<endl;
cout<<“n———————-“<<endl;
cout<<“1.Insertelement into the table”<<endl;
cout<<“2.Searchelement from the key”<<endl;
cout<<“3.Deleteelement at a key”<<endl;
cout<<“4.Exit”<<endl;
cout<<“Enteryour choice: “;
cin>>choice;
switch(choice) {
case 1:
cout<<“Enterelement to be inserted: “;
cin>>value;
cout<<“Enterkey at which element to be inserted: “;
cin>>key;
hash.Insert(key,value);
break;
case 2:
cout<<“Enterkey of the element to be searched: “;
cin>>key;
if(hash.Search(key) == -1 {
cout<<“Noelement found at key “<<key<<endl;
continue; }
else {
cout<<“Elementat key “<<key<<” : “;
cout<<hash.Search(key)<<endl;}
break;
case 3:
cout<<“Enterkey of the element to be deleted: “;
cin>>key;
hash.Remove(key);
break;
case 4:
exit(1);
default:
cout<<“nEntercorrect optionn”; } }
return 0;
}
Expert Answer
Answer to Please Update my following C++ code for Simple Hash Tables so it will Accept a Key as String and Map to String Value. P… . . .
OR

