Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Please! #include HashTable.h #include #include using namespace std; int main() { HashTable h(5); h.insert(Mary); h.insert(had); h.insert(a); h.insert(little); h.insert(lamb.); h.insert(It's); h.insert(fleece); h.insert(was); h.insert(white); h.insert(as); h.insert(snow);

C++ Please!

image text in transcribed

#include "HashTable.h" #include  #include  using namespace std; int main() { HashTable h(5); h.insert("Mary"); h.insert("had"); h.insert("a"); h.insert("little"); h.insert("lamb."); h.insert("It's"); h.insert("fleece"); h.insert("was"); h.insert("white"); h.insert("as"); h.insert("snow"); h.insert("And"); h.insert("everywhere"); h.insert("that"); h.insert("Mary"); h.insert("went,"); h.insert("that"); h.insert("lamb"); h.insert("was"); h.insert("sure"); h.insert("to"); h.insert("go."); h.print(); return 0; } 

An array of dynamic linked list objects. Could re-use class Dynamic, modified for use with string obiects HashTable FTTTtable: List -size: int -hash( key string): int (query) Hash function. Converts string to hash value, an nteger +HashTable( s int) +-HashTable() +clear) void tinsert key: string ): int +remove( key string) :int +find(key string): bool +isFull(): bool (query) +isEmpty(): bool (query) print) void (query) Use the above UML diagram and descriptions below to write a class that implements a Hash table. Your implementation should use open chaining to resolve collisions. You may provide additional class attributes, as you see fit, to complete the class. The above class has the following private attributes: table: This is a pointer to the object's dynamically allocated hash table. Used to create an array of Linked List objects size stores the number of elements in the hash table (the capacity). hash the hash function. It accepts the key string and returns the hash value The class has the following public attributes: constructor accepts an integer argument used to determine the number of elements in the hash table. Dynamically allocates the hash table destructor deallocates all dynamically allocated memory insert insert's it's argument into the hash table. calls the hash function to obtain an appropriate hash address. Returns 0 if successful, -1 otherwise remove removes the first key matching it's argument from the hash table. Returns 0 if successful, -1 otherwise find returns true if a key matching it's argument is found, false otherwise clear resets the object to it's initial state isFull-returns true if the structure is full, false otherwise isEmpty-returns true if the structure has no keys, false otherwise print displays all the keys currently stored in the structure Possible sample output from the print method: Bucket e: Head->white->snow->And->went, ->go. ->NULL Bucket 1 Head->had- >was->was- >NULL Bucket 2 Head->a->fleece->as->lamb- >sure->to->NULL Bucket 3: Head->lamb. >It's->that->that- >NULL Bucket 4: Head->Mary->1little->everywhere->Mary ->NULL The above is what the 5-element hash table looks like after inserting "Mary had a little lamb. It's fleece was white as snow And everywhere that Mary went, that lamb was sure to go

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

Discuss labor unrest in China.

Answered: 1 week ago