Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how can I implement this in c++ Homework using hashtable and function. const int STRTBL_NUM_BUCKETS = 1000; // a node in a linked list struct

how can I implement this in c++ Homework using hashtable and function. const int STRTBL_NUM_BUCKETS = 1000; // a node in a linked list struct StringTableEntry { std::string data; StringTableEntry* next = NULL; }; typedef StringTableEntry* StringTableRef; class StringTable { public: StringTable(); ~StringTable(); StringTableRef insert(string item); StringTableRef search(string searchName); string search(StringTableRef ref); void print(); void destruct(); private: StringTableRef bucket[STRTBL_NUM_BUCKETS]; int hash(string item); int hashVal; int numCollisions = 0; int numEntries = 0; }; 
#include #include #include "StringTable.h" int main(int argc, char** argv) { { // extra block to test the destructor StringTable t; string filename, aline, cmd; char ccmd; StringTableRef p; // open the input file if (argc < 2) return 0; filename = argv[1]; ifstream f; f.open(filename); if (f.fail()) return 0; // read test data and insert into string table, one line per item while (!f.eof() && !f.fail()) { getline(f, aline); t.insert(aline); } f.close(); t.print(); // how do I print the items. ccmd = '?'; while (ccmd != 'X' && ccmd != 'E') { cout << "Insert, Search, Print or Exit (I,S,P,X): "; getline(cin, cmd); ccmd = toupper(cmd[0]); switch (ccmd) { case 'I': cout << "Enter string: "; getline(cin, aline); t.insert(aline); break; case 'S': cout << "Enter string: "; getline(cin, aline); p = t.search(aline); // searching line? if (p) { cout << "Found search 1: " << p->data << endl; aline = t.search(p); cout << "Found search 2: " << aline << endl; } else cout << "Not found "; break; case 'P': t.print(); break; // How do I print case 'X': cout << "Testing destruct... "; t.destruct(); t.print(); break; default: cout << "Invalid input. Enter I,S,P or X "; } } } system("pause"); return 0; }

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago