Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In C++ Hash Table with Chaining Description In this assignment you are requested to implement a hash table that handles collisions by chaining. You have
In C++
Hash Table with Chaining Description In this assignment you are requested to implement a hash table that handles collisions by chaining. You have to use linked lists, either from the Standard Template Library (STL) (recommended) or by implementing your own. For usage of STL, refer for instance to http://w.cppreference.com/wiki You need to implement the insert, search and delete operations. The keys are integers (C++ int type) and you can assume that all keys are non-negative. The first number in the input will be the size m of the chained hash table. You will use the simple hash function h(kk mod m. Then lines will follow starting with 'i, "s', 'd%, or'e. The details are as follows: Use the hash function h(k) = k mod m. ike): Insert (key) into the table. For example, "i2" implies "Insert key 2 into the table." For collisions, insert the colliding key at the beginning of the linked list. You just need to insert the key and don't have to output anything in this case. d(key): delete (key) from the table. For example, d2 implies "Delete key 2 from the table." If there are multiple elements of the same key value, delete the element of the key value that appears the earliest in the list. If the delete was successful, you have to output (key) :DELETED If not (since there was no element with the key value), output key) DELETE FAILED s(key): search (kev) in the table. If there is an element with the key value, then you have to output key) FOUND_ATi,j where i is the hash table index and j is the linked list index. If there are multiple elements with the same key value, choose the first one appearing in the linked list. If you couldn't find the key, then output (key): NOT_FOUND; o: output the table. Output the entire hash table. Each line should begin with the slot/hash table index followed by key values in the linked list. For example, if m 3 and we inserted 3, 6, and 1 into an empty table in this order, then you should output e: finish your program. Example of input and output The following example shows an execution of the program in interactive mode. See the input files and output files under the testfiles folder for examples where input and output are separated. 12 i3 1:3-> 2: FOUND_ATO,1 S4 4: FOUND_ATO,2; d5 5: DELETE FAILED d2 :DELETED Hash Table with Chaining Description In this assignment you are requested to implement a hash table that handles collisions by chaining. You have to use linked lists, either from the Standard Template Library (STL) (recommended) or by implementing your own. For usage of STL, refer for instance to http://w.cppreference.com/wiki You need to implement the insert, search and delete operations. The keys are integers (C++ int type) and you can assume that all keys are non-negative. The first number in the input will be the size m of the chained hash table. You will use the simple hash function h(kk mod m. Then lines will follow starting with 'i, "s', 'd%, or'e. The details are as follows: Use the hash function h(k) = k mod m. ike): Insert (key) into the table. For example, "i2" implies "Insert key 2 into the table." For collisions, insert the colliding key at the beginning of the linked list. You just need to insert the key and don't have to output anything in this case. d(key): delete (key) from the table. For example, d2 implies "Delete key 2 from the table." If there are multiple elements of the same key value, delete the element of the key value that appears the earliest in the list. If the delete was successful, you have to output (key) :DELETED If not (since there was no element with the key value), output key) DELETE FAILED s(key): search (kev) in the table. If there is an element with the key value, then you have to output key) FOUND_ATi,j where i is the hash table index and j is the linked list index. If there are multiple elements with the same key value, choose the first one appearing in the linked list. If you couldn't find the key, then output (key): NOT_FOUND; o: output the table. Output the entire hash table. Each line should begin with the slot/hash table index followed by key values in the linked list. For example, if m 3 and we inserted 3, 6, and 1 into an empty table in this order, then you should output e: finish your program. Example of input and output The following example shows an execution of the program in interactive mode. See the input files and output files under the testfiles folder for examples where input and output are separated. 12 i3 1:3-> 2: FOUND_ATO,1 S4 4: FOUND_ATO,2; d5 5: DELETE FAILED d2 :DELETEDStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started