C++ Data Structure Homework Part A: Separate Chaining A hashtable of size 7 uses
ID: 3836733 • Letter: C
Question
C++ Data Structure Homework
Part A: Separate Chaining A hashtable of size 7 uses separate chaining to resolve collisions. A polynomial hash function where a = 33 is used. Sketch the table's contents after the following words have been added in the exact order shown: find, edge, body, race, plan, beat, they You may find it useful to create a list of lowercase letters and their ASCII numeric value. The letter a's value is 97 and z's value is 122. Part B: Linear Probing: A hashtable of size 7 uses linear probing to resolve collisions. Using Part A's polynomial hash function and sequence of words, sketch the table's contents after the words have been added.Explanation / Answer
#include #include #include #include using namespace std; const int TABLE_SIZE = 128; /* * HashNode Class Declaration */ class HashNode { public: . int key; int value; HashNode* next; HashNode(int key, int value) { this->key = key; this->value = value; this->next = NULL; } }; /* * HashMap Class Declaration */ class HashMap { private: HashNode** htable; public: HashMap() { htable = new HashNode*[TABLE_SIZE]; for (int i = 0; i next; } if (entry == NULL) { entry = new HashNode(key, value); if (prev == NULL) { htable[hash_val] = entry; } else { prev->next = entry; } } else { entry->value = value; } } /* * Remove Element at a key */ void Remove(int key) { int hash_val = HashFunc(key); HashNode* entry = htable[hash_val]; HashNode* prev = NULL; if (entry == NULL || entry->key != key) { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.