Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement HashTable class, which is class template. The default constructor uses 3 as the table size. The constructor with parameter uses the parameter value as

Implement HashTable class, which is class template. The default constructor uses 3 as the table size. The constructor with parameter uses the parameter value as the table size. Do not hard-code array size in your constructors. Let the user decide what array size will be.

#include #include "SLL.h" using namespace std;

template class HashTable { int tableSize; // table size SLL* table; public: // default constructor, which uses default table size 3 HashTable(){ tableSize = 3; table = new SLL[tableSize]; } // constructor, which use size as the table size HashTable(int size){ // implement this method } // search item in the table // if found, return true; otherwise, return false bool find(V item){ // implement this method } // insert (item1, item2) to the table // use item1 as the key // if inserted, return true // otherwise, return false bool insert(V item1, V item2){ //implement this method } // delete the pair whose key value is item // if deleted, return true // otherwise, return false bool erase(V item){ // implement this method }

};

SLL.h

#include #include #include "node.h" using namespace std;

template class SLL { Node * headPtr; int size; public: // default constructor SLL(){ headPtr = nullptr; size = 0; } // destructor ~SLL(){ Node *next; while(headPtr != nullptr) { next = headPtr->next; delete headPtr; headPtr = next; } } Node* getHeadPtr(){ return headPtr; } // insert (item1, item2) to the list void insert(U item1, U item2){ Node *n = new Node(); n->SSN = item1; n->name = item2; n->next = nullptr; if(headPtr == nullptr) headPtr = n; else { Node last = headPtr; while(last->next != nullptr) last = last->next; last->next = n; } size++; } // if find the item1 value, return the pointer to the node // otherwise, return nullptr Node* search(U item1){ Node *curr = headPtr; while(curr != nullptr) { if(curr->item1 == curr->SSN) return curr; curr = curr->next; } return nullptr;//not found } // remove the node with key value: item1 bool remove(U item1){ Node *prev = nullptr, *curr = headPtr; while(curr != nullptr) { if(curr->SSN == item1) break; prev = curr; curr = curr->next; } if(curr == nullptr) //not found return false; if(curr == headPtr) //remove head node? headPtr = curr->next; else prev->next = curr->next; delete curr; size--; return true; } int getSize(){ return size; } // display the SSN values of each node in the linked list void display(){ Node* temp; temp = headPtr; while (temp!= nullptr) { cout << temp->SSN << endl; temp = temp->next; } } };

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

Step: 3

blur-text-image

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

ISBN: 1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

Were they made on a timely basis?

Answered: 1 week ago

Question

Did the decisions need to be made, or had they already been made?

Answered: 1 week ago

Question

When there was controversy, was it clear who had the final say?

Answered: 1 week ago