Need help on the Trend File Output section as well as the main code. Last two pi
ID: 3687570 • Letter: N
Question
Need help on the Trend File Output section as well as the main code. Last two pictures are the correct hashtag.cpp file.Explanation / Answer
#include #include #include using namespace std; const int TABLE_SIZE = 5; /* * HashNode Class Declaration */ class HashNode { public: int key; int value; HashNode(int key, int value) { this->key = key; this->value = value; } }; /* * DeletedNode Class Declaration */ class DeletedNode:public HashNode { private: static DeletedNode *entry; DeletedNode():HashNode(-1, -1) {} public: static DeletedNode *getNode() { if (entry == NULL) entry = new DeletedNode(); return entry; } }; DeletedNode *DeletedNode::entry = NULL; /* * HashMap Class Declaration */ class HashMap { private: HashNode **htable; public: HashMap() { htable = new HashNode* [TABLE_SIZE]; for (int i = 0; i key == key) htable[hash_val]->value = value; } } else htable[hash_val] = new HashNode(key, value); } } /* * Search Element at a key */ int Search(int key) { int hash_val = HashFunc(key); int init = -1; while (hash_val != init && (htable[hash_val] == DeletedNode::getNode() || htable[hash_val] != NULL && htable[hash_val]->key != key)) { if (init == -1) init = hash_val; hash_val = HashFunc(hash_val + 1); } if (htable[hash_val] == NULL || hash_val == init) return -1; else return htable[hash_val]->value; } /* * Remove Element at a key */ void Remove(int key) { int hash_val = HashFunc(key); int init = -1; while (hash_val != init && (htable[hash_val] == DeletedNode::getNode() || htable[hash_val] != NULL && htable[hash_val]->key != key)) { if (init == -1) init = hash_val; hash_val = HashFunc(hash_val + 1); } if (hash_val != init && htable[hash_val] != NULL) { delete htable[hash_val]; htable[hash_val] = DeletedNode::getNode(); } } }; /* * Main Contains Menu */ int main() { HashMap hash; int key, value; int choice; while(1) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.