Question: Fill C + + code please This lab is to practice with a Hash Table that contains int values and uses probing. Your code will
Fill C code please
This lab is to practice with a Hash Table that contains int values and uses probing. Your code will NOT make
use of any premade hash table libraries or classes you are to build the methods yourself, using a
dynamicallyallocated array to hold the table's values.
Define a class named HashTable that has the following methods. You may assume that only
nonnegative integer values will be placed into the HashTable.
T is the data type of the values in the table it's currently set to unsigned int using a typedef statement
Define a private method not available to users of the class! named hashFunc that performs the
hashing function for the HashTable. It should expect the value to be inserted in the table and return
a value from to tableSize where tableSize is the size of the HashTable. My recommended
coding just for fun, and the way it will be tested is to have it return return the square of the value
modulo size, or value value tableSize, but you are free to try other hasing functions if you'd
like.
int HashTable::hashFuncT value const
Two other private methods are prewritten for you:
nextIndex calculates the next index inThis lab is to practice with a Hash Table that contains int values and uses probing. Your code will NOT make
use of any premade hash table libraries or classes you are to build the methods yourself, using a
dynamicallyallocated array to hold the table's values.
Define a class named HashTable that has the following methods. You may assume that only
nonnegative integer values will be placed into the HashTable.
T is the data type of the values in the table it's currently set to unsigned int using a typedef statement
Define a private method not available to users of the class! named hashFunc that performs the
hashing function for the HashTable. It should expect the value to be inserted in the table and return
a value from to tableSize where tableSize is the size of the HashTable. My recommended
coding just for fun, and the way it will be tested is to have it return return the square of the value
modulo size, or value value tableSize, but you are free to try other hasing functions if you'd
like.
int HashTable::hashFuncT value const
Two other private methods are prewritten for you:
nextIndex calculates the next index in the hash table in the probing sequence. As currently
written, it uses Linear Probing. It's very useful to make this a separate function, as it will allow
for different probing sequences! NOTE: This method uses Call By Reference to mutate the
variable passed to it
bucketAvailable returns true if the bucket is available during an insert operation do NOT use for
search or delete!
Constructors a zeroargument constructor, and one that expects a size of the table, which is the
number of items the HashTable can hold. The constructor should dynamically allocate the array or
use a vector of type T of the appropriate size, and the bool array of the same size, initialized to all
false, to keep track of whether a value has been deleted from the table remember in probing, you
don't empty the bucket when you delete a value, you just mark it as "deleted" Only positive
integers should be inserted into the table in this lab, so you can initialize the table's values to
HashTable::HashTableint size
A method to insert a value into the HashTable that returns true if the value is successfully inserted
and false if there is no room left in the HashTable for the value to be stored. the method should
search the HashTable for an available spot and use nextIndex as appropriate until it either finds an
empty bucket or until the entire array has been checked for an open bucket. Don't forget to check
the bool array for deleted values, as a bucket containing a deleted value can be reclaimed for inserting the new value and set the bool back to false when you do insert!
Last of the code from last image:
cout myTabledeleteValue endl;
cout Printing out the halffilled hash table
;
myTableprintTable;
cout endl;
cout Inserting a few new values into the table
;
for int i; i ; i
cout myTableinsertValue i;
cout endl;
cout "Search for the new values and one that isn't there
;
for int i; i ; i
cout myTablesearchValue i;
cout endl;
cout Printing out the final hash table
;
myTableprintTable;
cout endl;
delete myTable;
return EXITSUCCESS;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
