Question: Please provide the correct solution to the following C++ assignment. The correct solution will receive a thumbs up as soon as its tested. Also, you

Please provide the correct solution to the following C++ assignment.

The correct solution will receive a thumbs up as soon as its tested.

Also, you can take as much time as you need. I will give a thumbs up even if it takes you ton of time to figure out the answer.

Lastly, if you can add comments to your code, that would be extremely appreciated. If not, it's fine.

Thanks

=========================================================

=========================================================

=========================================================

Your goal is to implement hash tables for Phone Directory.

=========================================================

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.

// Probing function, returns location to check on iteration iter

// starting from initial value val.

int probeFunction(int val, int iter);

void init(int tsizei);

int hash(string key);

// A couple of hash functions to use.

int sillyHash(string key);

int smarterHash(string key);

public:

// Insert a (key,value) pair into table. Returns true if successful, false if not.

bool insert(string key, int value);

bool remove(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.

bool lookup(string key, int& value);

// Modify a (key,value) pair in hash table. Changes value to value if found and returns true, returns false if key not in table.

bool modify(string key, int value);

// Return an array of all the keys in the table. Stores these nkeys in array keys.

void getKeys(string*& all_keys, int& nkeys);

// Return the number of (key,value) pairs currently in the table.

int numStored();

// Create a default sized hash table.

Phonedirectory();

// Create a hash table that can store nkeys keys (allocates 4x space).

Phonedirectory(int nkeys);

~Phonedirectory();

// Print the contents of the hash table data structures, useful for debugging.

void printTable();

};

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!