April 2018
Intermediate to advanced
322 pages
6h 57m
English
By iterating the hash table, we can collect the pairs of key and value, then print them to the screen. We will use this PrintHashTable() operation to see if the new element we insert is stored in the right place. The implementation of the operation will be as follows:
void HashTable::PrintHashTable(){ // Iterate through array for(int i = 0 ; i < currentSize; ++i) { // Just print the element // if it exist if(arr[i] != NULL && arr[i]->Key != -1) { cout << "Cell: " << i; cout << " Key: " << arr[i]->Key; cout << " Value: " << arr[i]->Value; cout << std::endl; } }}
Since the operation will iterate through the hash table until the size of the table, the time complexity of this operation is O(TABLE_SIZE) ...