April 2018
Intermediate to advanced
322 pages
6h 57m
English
Sometimes, we need to check whether a hash table is empty or not. To do so, we can check if each cell in the hash table has a list that contains at least one element. The implementation of the IsEmpty() operation should be as follows:
bool HashTable::IsEmpty(){ // Initialize total element int totalElement = 0; // Count all elements in table hash for (int i = 0; i < TABLE_SIZE; ++i) { totalElement += (int)tableList[i].size(); // If the total element is not zero // the hash table must not be empty if totalElement > 0 return false; } // If this statement is reached // it means that total element is zero return true;}
As we can see in the preceding function implementation, we have to iterate the hash table and ...