Now that you have a working implementation of the HashNode and HashTable classes, you can convert them to templates, and update main.cpp to match with the new template classes. In order for everything to work you will also have to: - overload the == operator for the Student class - declare the hash function a friend function of the Student class - send the hash function as an argument to insert, remove, and search functions.
17 lines
373 B
C++
17 lines
373 B
C++
// Implementation file for the Student class
|
|
// Written By: Iurii Tatishchev
|
|
|
|
#include <string>
|
|
#include "Student.h"
|
|
|
|
/*~*~*~*
|
|
Hash function: takes the key and returns the index in the hash table
|
|
*~**/
|
|
int key_to_index(const Student &key, int size) {
|
|
string k = key.name;
|
|
int sum = 0;
|
|
for (int i = 0; k[i]; i++)
|
|
sum += k[i];
|
|
return sum % size;
|
|
};
|