Question
C++: 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
C++: 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.
My project is use hash table to storage a pile of strings with linked list, then output those strings in sorted order. those pile of string in text file, need read and write string text file , output should be in sorted order(the string text file giving on the end)
implement a hash table of 29 buckets to store string data.
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. The output
format is given below.
outFile2 (use argv [3]): All debugging outputs, for your eyes only!
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) { cout
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
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