Question
Please provide the correct solution to the following C++ assignment. The correct solution will receive a thumbs up as soon as its tested. Lastly, if
Please provide the correct solution to the following C++ assignment.
The correct solution will receive a thumbs up as soon as its tested.
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.
probing function, the init function, sillyhashing, smarterhashing, and the getkeys function
=========================================================
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started