Question: c++ Program: My project is hash table using single linked list to storage a pile of strings , then output those strings in sorted order.

c++ Program: My project is hash table using single linked list to storage a pile of strings , then output those strings in sorted order. those pile of string need read from a text file, and output should be in sorted order(the string in text file giving on the end)

my code has not compile error, but the output is empty. the pile of strings did not write into output file.Please help me fix the errors.

II. inFile (use argv [1]): A text file contains a list of English words (strings).

II. outFile1 (use argv [2]): The final result of the hash table: 29 ordered linked list.

outFile2 (use argv [3]): All debugging outputs, for your eyes only!

The output format is given below.

hashTableAry[index] to a given outFile, using 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: if index is 29

hashTable [29] -> ( dummy, 0, Adam) -> (Adam, 1, Ben) -> (Ben, 2, Brian) -> (Brian, 2, Chuck)........................ -> NULL

my code:

#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) { coutnext; } 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 << ' '; } } }

string in text file(test.txt)

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

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!