Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an integer array of size 30. Assign -1 to each location in the array indi

ID: 3825968 • Letter: C

Question

Create an integer array of size 30. Assign -1 to each location in the array indicating that the array is empty. Populate half of the array with random integer values between 100 and 500 inclusive. Use the following formula in order to hash and store each number in its proper position/location. Generated Number Table Size: Should a collision occurs, use linear probing to find next available position location. Use the following probing hashing function. Generated Number 1 Table Size; Display and introduction message followed by the generated array. The generated array should be displayed in 2 lines. Each line contain 15 numbers separated by 2 spaces

Explanation / Answer

/* * C++ Program to Implement Hash Tables with Linear Probing */ #include #include #include using namespace std; const int TABLE_SIZE = 30; /* * 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) { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote