Has anyone answered this question yet? http://www.chegg.com/homework-help/questi
ID: 3832586 • Letter: H
Question
Has anyone answered this question yet? http://www.chegg.com/homework-help/questions-and-answers/c-programplease-help-figure--give-sample-code-two-collision-resolution-open-addressing-cha-q21490967
Explanation / Answer
#include #include #include using namespace std; const int TABLE_SIZE = 5; class HashNode { public: int key; int value; HashNode(int key, int value) { this->key = key; this->value = value; } }; 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; 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); } } 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; } 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(); } } }; 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.