Related questions
The images I have uploaded are the part 1 to 4 and questions below are continue on the questions uploaded
5. C++ Class Template with Method Stubs
#pragma once
#include <iostream>
#include <string>
#include <stdexcept>
#include <
template <typename T>
class HashTable {
private:
struct Entry {
std::string key;
T value;
bool isOccupied;
bool isDeleted;
Entry() : key(""), value(), isOccupied(false), isDeleted(false) {}
};
Entry* table;
size_t capacity;
size_t size;
double loadFactorThreshold;
size_t customHash(const std::string& key) const {
size_t hash = 5381;
for (char c : key) {
hash = ((hash << 5) + hash) + c;
}
return hash;
}
size_t probe(const std::string& key, bool forInsert = false) const;
void resize();
public:
// Constructor
HashTable(size_t initialCapacity = 101);
// Big Five
~HashTable(); // Destructor
HashTable(const HashTable& other); // Copy constructor
HashTable& operator=(const HashTable& other); // Copy assignment
HashTable(HashTable&& other) noexcept; // Move constructor
HashTable& operator=(HashTable&& other) noexcept; // Move assignment
// Core methods
void insert(const std::string& key, const T& value);
T& get(const std::string& key);
void remove(const std::string& key);
bool contains(const std::string& key) const;
size_t getSize() const { return size; }
size_t getCapacity() const { return capacity; }
};
6. Testing and Verification
Test Cases:
- Insert and retrieve values (int, string, custom structs)
- Insert duplicate key (should overwrite or update)
- Delete key and re-insert
- Trigger resize
- Collision resolution (manually induce collisions)
7. Application: Leetcode Problem Solving
Problem 1: Two Sum
- Use your HashTable <int> to store value → index mapping
- Lookup complement in O(1) time
Problem 2: Group Anagrams
- Use HashTable<std::vector<std::string>>
- Key = sorted version of each string
8. Deliverables
- HashTable.h or .cpp file with complete implementation
- Test program (main.cpp) demonstrating:
- Unit tests
- At least 2 Leetcode problems solved using your hash table
- Optional README documenting:
- Your hash strategy
- Collision resolution method
Step by stepSolved in 2 steps
- Text book imageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningText book imageSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningText book imageNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
- Text book imageText book imageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrText book imageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT