Question: C++ CONVERT THE LINKED LIST TO AN ARRAY-BASED unique pointer template struct Node : public manageMemory { Node* backward; Node* forward; string key; T data;
C++ CONVERT THE LINKED LIST TO AN ARRAY-BASED unique pointer
template
struct Node : public manageMemory {
Node* backward;
Node* forward;
string key;
T data;
};
template
class linkedList : public manageMemory
{
public:
linkedList() {
first = NULL;
last = NULL;
count = 0;
}
~linkedList() {
Node
while (first != NULL) {
temp = first;
first = first->forward;
delete temp;
count--;
}
}
int getCount() const; //should be public
void insertLast(const string& key, const T& value);
bool keyExists(const string& key);
T& getDataForKey(const string& key);
void deleteNodeContainingKey(const string& key);
private:
Node
Node
int count;
};
template
class hashTable : public manageMemory
{
private:
int hash(const string& key); //should be private
linkedList
public:
int getWorstClump() const; //should be public
int getTotalCount() const; //should be public
void add(const string& key, const T& value) {
arr[hash(key)].insertLast(key, value);
}
const bool exists(const string& key) {
return arr[hash(key)].keyExists(key);
}
T& item(const string& key) {
return arr[hash(key)].getDataForKey(key);
}
void remove(const string& key) {
arr[hash(key)].deleteNodeContainingKey(key);
}
T& operator[](const string& key) {
return item(key);
}
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
