Question: Please help me fix the error and give sorted output .(my program is implement a hash table of 29 buckets to store string data in

Please help me fix the error and give sorted output.(my program is implement a hash table of 29 buckets to store string data in sorted)

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 test 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

#include

using namespace std;

const int TABLE_SIZE = 128;

class HashNode

{

public:

. int key;

int value;

HashNode* next;

HashNode(int key, int value)

{

this->key = key;

this->value = value;

this->next = NULL; }

};

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;

}

int HashFunc(int key)

{

return key % TABLE_SIZE;

}

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;

}

}

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"<

}

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

flag = true;

}

entry = entry->next;

}

if (!flag)

return -1; }

};

int main(int argc, char *argv[])

{

ifstream in("test.txt");

ofstream outfile("encfile.txt");

if(!in) {

cout << "Cannot open input file. ";

return 1;

}

char str[10000];

char encStr[10000];

while(in) {

in.getline(str, 10000); // delim defaults to ' '

if(in)

{

int i=0;

cout << str << endl;

for(i=0;str[i]!='\0';i++)

encStr[i]='\0';

outfile << encStr << ' ';

}}

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!