Question
please add driver program for the code giving below:(my program is implement a hash table of 29 buckets to store string data) you should reading
please add driver program for the code giving below:(my program is implement a hash table of 29 buckets to store string data)
you should reading and writing in text file, use argv[ ]. (reading input from text file, (string in text file giving below) print the list to outFile, from listHead to the end of the list in the following format:
hashTable[index] -> (this node data, this nodes count, next nodes data) -> (this node data, this nodes count, next nodes data) -> . . . . . -> NULL
For example: index is 29
hashTable [29] -> ( dummy, 0, Adam) -> (Adam, 1, Ben) -> (Ben, 2, Brian) -> (Brian, 2, Chuck)........................ -> NULL
string in text file
Hishaam Esteban Kevin Matthew Brandon Joel Luis Jianwei Yechiel Taeyong Jiayu Jiade Phillip Russell Mohebullah Akshar Evgeniia Andres Marco Justin Robin Kelvin Zhiheng Jeffrey Yifei Yinyu Jiaxin Youyia Eleftherios Yuan Resfred Danielle Jason Lin ZhengZhong Han Chandra Conghui Christopher Christina Rashad Aaron Gregory Xihao Yuhuan Niraj Logan Ba Khoi Jiade Pinpin Seth Jacb Russell Win Thurein Karamvir Andres Shadman Rani Prince Patricio Christopher Angelo Denny Laert Zhiheng Taejoon Heesun Joseph Bee Sim Kenny Jasmin Ben Qisheng Michael Cheng Brandon Peter Oscar Qi Juan Brian Colin Harmandeep Brian Wei Yangfan Emanuel Huihui Cesar Shuhua
#include
#include
#include
#include
using namespace std;
const int TABLE_SIZE = 128;
/*
* HashNode Class Declaration
*/
class HashNode
{
public:
. int key;
int value;
HashNode* next;
HashNode(int key, int value)
{
this->key = key;
this->value = value;
this->next = NULL; }
};
/*
* HashMap Class Declaration
*/
class HashMap
{
private:
HashNode** htable;
public:
HashMap()
{
htable = new HashNode*[TABLE_SIZE];
for (int i = 0; i < TABLE_SIZE; i++)
htable[i] = NULL;
}
~HashMap()
{
for (int i = 0; i < TABLE_SIZE; ++i)
{
HashNode* entry = htable[i];
while (entry != NULL)
{
HashNode* prev = entry;
entry = entry->next;
delete prev;
}
}
delete[] htable;
}
/*
* Hash Function
*/
int HashFunc(int key)
{
return key % TABLE_SIZE;
}
/*
* Insert Element at a key
*/
void Insert(int key, int value)
{
int hash_val = HashFunc(key);
HashNode* prev = NULL;
HashNode* entry = htable[hash_val];
while (entry != NULL)
{
prev = entry;
entry = entry->next;
}
if (entry == NULL)
{
entry = new HashNode(key, value);
if (prev == NULL)
{
htable[hash_val] = entry; }
else
{ prev->next = entry;
}
}
else
{
entry->value = value;
}
}
/*
* Remove Element at a key
*/
void Remove(int key)
{
int hash_val = HashFunc(key);
HashNode* entry = htable[hash_val];
HashNode* prev = NULL;
if (entry == NULL || entry->key != key)
{
cout<<"No Element found at key "< return;}while (entry->next != NULL){prev = entry;entry = entry->next;}if (prev != NULL){prev->next = entry->next;}delete entry;cout<<"Element Deleted"< }/** Search Element at a key*/int Search(int key){bool flag = false;int hash_val = HashFunc(key);HashNode* entry = htable[hash_val];while (entry != NULL){if (entry->key == key){cout<value<<" "; flag = true;}entry = entry->next;}if (!flag)return -1; }};
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