This assignment is for the students to practice to use hashingwith chaining to implement a simple hash table.
/*** Inserts the data into the correct index. For insertion, we wantO(1) time, so we will insert in the front of the list.** This function will simply do the followings:* 1. hash the data key to get the appropriate index in the hashtable* 2. insert the data key into the appropriate index* (for inserting the data in the beginning of the STL list, we usethe .push_front() method in the list,* the push_front() method will accept the data we want toinsert)** @param data, int, the data we want to insert in the hashtable**/
}
false. *
* * *
* * * *
The iterator type should be:list<int>::iterator it = find(first_iterator, last_iterator,x);
But for convience, other than writing such long and complicatedtype, we can replace it with auto, that is:
* otherwise, it will return true (because it is pointingto some found item). **/
}
/*** Removes the data if it exists in the list, if it does not exist,end the function.* (As we still need to find that data before we remove, so thisfunction is pretty similiar
* This function will do the followings:* 1. Same as search() point 1* 2. Same as search() point 2* 3. If the iterator is the end of the list, it will return thefunction (cancel the
the data in the hash table *
*/
}
Requirements:
1) Follow the comments of the functions tocomplete the code of insert(),search()and remove().
2) When you finish the insert(),search()and remove()functions, run the code in main.cpp, butdo not change the testing code in main.cpp.
3) Rename the execution fileto hashing.
Correct output of the program:
| 0|->52 | 1|->92 | 2|->28 | 3|->
| 4|->| 5|->| 6|->| 7|->72->20 | 8|->
| 9|->48| 10 | -> 10 -> 36 | 11 | ->| 12 | ->
This assignment is for the students to practice to use hashing with chaining to implement a simple hash table. /** * Ins
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am