Question: write a class named HashTable that implements a hash table using linear probing to resolve collisions. Submit your solution in it's own header file named
write a class named HashTable that implements a hash table using linear probing to resolve collisions.
Submit your solution in it's own header file named HashTable.h.
Your solution should include the following methods in its public interface:
insert() - accepts a string as its only argument, which is added to the hash table, setting the element's mark where it is stored to 2.
remove() - accepts a string as its only argument, and removes the string from the hash table (if found) by setting its mark to 1.
isFull() - returns true if the hash table is full, false otherwise.
isEmpty() - returns true if the hash table is full, false otherwise.
find() - accepts a string as its only argument. Returns true if it is found in the hash table, false otherwise.
clear() - empties the hash table by setting each element's mark to 0.
print() - displays the contents of the hash table to the screen.
constructor - accepts an integer as its only argument, creating a hash table that can store that many values (a dynamically allocated array of Elements).
destructor - frees all memory used.
Other than the print() method, none of these methods should interact with the user in any way.
Here's a list of private attributes:
Element - a nested struct containing the following fields:
key - Stores the string passed to the object through the insert method.
mark - a variable set to 2 if the element is being used, 1 if it was used but then was deleted, and 0 if it was never used.
table - an Element pointer that holds the memory address of a dynamically allocated array of Elements.
size - stores the size of the Element array.
hash - The hash function. It accepts a String as its only argument and returns an index into the hash table.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
