Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago