Question: Use class that I provided below. You ARE NOT ALLOWED to use any data structure or algorithm related function from the C + + standard

Use class that I provided below.
You ARE NOT ALLOWED to use any data structure or algorithm related function from the C++ standard template library (STL) or any other external libraries.
Main method MUST be in Subtask1.cpp class
#ifndef HOMEWORK3_HASHTABLE_H
#define HOMEWORK3_HASHTABLE_H
#include
#include
class HashTable {
private:
public:
HashTable();
~HashTable();
void insert(const std::string& key);
bool search(const std::string& key);
static const int TABLE_SIZE =100;
struct Node {
std::string key;
Node* next;
Node(const std::string& key) : key(key), next(nullptr){}
};
Node* table[TABLE_SIZE];
};
#endif
//HashTable.cpp class
#include "HashTable.h"
HashTable::HashTable(){
for (int i =0; i TABLE_SIZE; ++i){
table[i]= nullptr;
}
}
HashTable::~HashTable(){
for (int i =0; i TABLE_SIZE; ++i){
Node* current = table[i];
while (current != nullptr){
Node* temp = current;
current = current->next;
delete temp;
}
}
}
void HashTable::insert(const std::string& key){
int hash =0;
for (char c : key){
hash =(hash *256+ c)% TABLE_SIZE;
}
Node* newNode = new Node(key);
newNode->next = table[hash];
table[hash]= newNode;
}
bool HashTable::search(const std::string& key){
int hash =0;
for (char c : key){
hash =(hash *256+ c)% TABLE_SIZE;
}
Node* current = table[hash];
while (current != nullptr){
if (current->key == key){
return true;
}
current = current->next;
}
return false;
}
Use class that I provided below. You ARE NOT

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!