Find Jobs
Hire Freelancers

Modify the key type in the class definition to a string - 27/04/2018 21:40 EDT

$10-25 USD

Në vazhdim
Postuar almost 6 years ago

$10-25 USD

Paguhet në dorëzim
Header below defines a class for simple hash table int hash(string key) { hashCode = 0; for (int i = 0; I < [login to view URL](); ++I) { hashCode = hashCode + I % key[I]; } hashIndex = hashCode % TABLE_SIZE; return hashIndex; ----------------------------------------------------------------------------------------------------------- #ifndef hashMap_h #define hashMap_h #include<iostream> #include<string> using namespace std; class HashEntry { public: int key; string value; HashEntry(int key, string value) { this->key = key; this->value = value; } }; //============================================ const int TABLE_SIZE = 11; class HashMap { private: HashEntry * *table; public: HashMap() { table = new HashEntry*[TABLE_SIZE]; for (int i = 0; i < TABLE_SIZE; i++) table[i] = nullptr; } bool find(int key, string& value) { // return value associated with key // return -1 if not found int hash = (key % TABLE_SIZE); while (table[hash] != nullptr && table[hash]->key != key) hash = (hash + 1) % TABLE_SIZE; //linear probe if (table[hash] == nullptr) return false; // not found else //table[hash]->key != key { value = table[hash]->value; return true; } } void insert(int key, string value) { //Insert <key, value> pair using hassh function int hash = (key % TABLE_SIZE); int count = 1; while (count < TABLE_SIZE && table[hash] != nullptr && table[hash]->key != key) { hash = (hash + 1) % TABLE_SIZE; ++count; } if (count >= TABLE_SIZE) { cout << " Hash table is full!!" << endl; return; } if (table[hash] != nullptr) delete table[hash]; table[hash] = new HashEntry(key, value); } void display() { // used for debugging purpose only to inspect what's in the map for (int i = 0; i < TABLE_SIZE; ++i) { if (table[i] == nullptr) { cout << "[" << i << ", Nil, Nil" << "]" << endl; } else { cout << "[" << i << ", " << table[i]->key << ", " << table[i]->value << "]" << endl; } } cout << endl; } ~HashMap() { for (int i = 0; i < TABLE_SIZE; i++) if (table[i] != nullptr) delete table[i]; delete[] table; } }; #endif /* hashMap_h */ 2. Modify the key type in the class definition to a string, e.g. phone number or e-mail address. Use the string hash function discussed in class or search online for alternative functions that work on strings.
ID e Projektit: 16807111

Rreth projektit

1 propozim
Projekt në distancë
Aktive 6 yrs ago

Po kërkoni të fitoni para?

Përfitimet e ofertës për Freelancer

Vendosni buxhetin dhe afatin tuaj
Paguhuni për punën tuaj
Përshkruani propozimin tuaj
Është falas të regjistrohesh dhe të bësh oferta për punë
1 freelancer is bidding on average $22 USD for this job
Avatari i Përdoruesit
Dear sir I have full experience of java and c program I read your description carefully I ever done similar problem in c++ I am full confident to complete your project and I do my best if you let me bid on yours. I focus on client's credit than money. I want to discuss more in detail. Thank you.
$22 USD në 10 ditë
5,0 (11 përshtypje)
2,9
2,9

Rreth klientit

Flamuri i UNITED STATES
Missouricity, United States
5,0
29
Mënyra e pagesës u verifikua
Anëtar që nga korr 9, 2015

Verifikimi i klientit

Faleminderit! Ne ju kemi dërguar me email një lidhje për të kërkuar kredinë tuaj falas.
Ndodhi një gabim gjatë dërgimit të email-it tuaj. Ju lutemi provoni përsëri.
Përdorues të regjistruar Punë të postuara
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Po ngarkohet shikimi paraprak
Leja u dha për Geolocation.
Seanca e hyrjes ka skaduar dhe ke dalë. Hyr sërish.