Hello guys I need help with creating the framework behind a current project. I am not going to ask you to do it for me, I just need some guidance.
My task is to implement an adjacency list in C++, which will consist of nodes that will store a string (the name of the city) as well as an integer to represent the "total distance in meters" between 2 nodes (cities). I will be given a document consisting of the different pathways between nodes and the number of meters each node is seperated by. At the bottom is a link to just a picture of what I'm trying to make.
I am trying to make a class called DLL which will contain a struct called "node" to hold the needed values.
class DLL {
private:
struct Node {
string nameOfCity;
Node *next;
//Node *prev;
int distance;
};
Node *head = nullptr; //last element
Node *tail = nullptr; //1st element
public:
DLL() { //new left-hand side node
Node *head = nullptr;
}
DLL(string pCityName, int pCost)
{
Node *n = new Node;
n->nameOfCity = pCityName;
n->distance = pCost;
n->next = nullptr;
}
~DLL()
{
while(head != nullptr)
{
Node *n = head->next;
delete head;
head = n;
}
}
void addNode(string pName)
{
Node *n = new Node;
n->nameOfCity = pName;
//n->prev = nullptr;
n->next = head;
head = n;
}
};
Am I on the right track?
Also, another question: I want the left-hand side (see the picture) list to be a doubly linked list, but the nodes on the right side singly linked. How do I accomplish this?