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 * temp;

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* first;

Node* last;

int count;

};

template

class hashTable : public manageMemory

{

private:

int hash(const string& key); //should be private

linkedList arr[1000];

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

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 Databases Questions!