April 2018
Intermediate to advanced
322 pages
6h 57m
English
To insert a new pair of int and string to the hash table, we need to find out a hash key for the inputted key. Then, we traverse to chaining node in the cell pointed by the hash key to find if the the given new pair data exists. For instance, if the hash key is 5, we just need to go to cell 5 then traverse to the list in that cell to find out the inputted key. If the inputted key is found, we update the value of that key. If the key is not found, we add the pair of data to the back of the list. The implementation of Insert() operations should be as follows:
void HashTable::Insert(int key, string value){ bool isKeyFound = false; // Get hash key from hash function int hashKey = HashFunction(key); // Iterate ...