Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions

Question

List the components of the strategic management process. page 72

Answered: 1 week ago

Question

3 How the market system answers four fundamental questions.

Answered: 1 week ago