Question: C++ I need help writing the functions for this hash table class. All I need is the hash function(I already wrote something in this function

C++ I need help writing the functions for this hash table class. All I need is the hash function(I already wrote something in this function but not sure if it correct), insert function, lookup function(search), and probeFunction. Eveything else you can keep blank unlest somehow they associate with one another. Thanks. ____________________________________________________________________________________________________________________________________________________

#include #include using namespace std; class Phonedirectory { private: int tsize; int nstored; // number of keys stored in table string *keys; int *values; int *sentinels; // 0 if never used, 1 if currently used, -1 if previously used. static const int curr_used = 1; static const int never_used = 0; static const int prev_used = -1; static const int default_size = 10000; // Default size of table. int probeFunction(int val, int iter); // Probing function, returns location to check on iteration iter starting from initial value val. void init(int tsizei); int hash(string key) { //Not sure if correct. If not please change else delete this note. int sum = 0; for (int k = 0; k < key.length(); k++) { int n = key[k] - '0' sum = sum + n; } return sum % default_size; } public: bool insert(string key, int value); // Insert a (key,value) pair into table. Returns true if successful, false if not.

bool remove(string key, int value); bool lookup(string key, int& value); // Lookup a key in hash table. Copies value to value if found and returns true, returns false if key not in table. void getKeys(string*& all_keys, int& nkeys); // Return an array of all the keys in the table. Stores these nkeys in array keys. int numStored(); // Return the number of (key,value) pairs currently in the table. Phonedirectory(); // Create a default sized hash table. Phonedirectory(int nkeys); // Create a hash table that can store nkeys keys (allocates 4x space). ~Phonedirectory(); void printTable(); // Print the contents of the hash table data structures, useful for debugging.

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!