Okay, I have to store an adjacency matrix for a graph problem I'm doing. Let's use this picture to explain it right now. Click here I figured, I'm use a linked list to store it where each node uses the struct
struct Node
{ char item;
Node* vertex;
Node* next; };
Where item would be either A, B, C, D; vertex would point to another list that said what each pointed to (i.e. In the node A, there would be a B and C in the vertex list), and the next would point to the next item.
The list that vertex pointed to would use this struct.
struct VNode
{ char item;
int val;
VNode* next; };
To put it into a visual sense, this is what my picture came out to be. Click here
When the program reads it, it should find the vertex it's in (say A), go into the vertex list, and look at the values there to figure out which is the lowest (hence why I designed it that way).
Now, I'm not sure if this is the best way to handle it or not, but I'm not told how many I'll need and I don't know vectors yet so this is what I'm trying.
My question is that am I gonna have to use two list classes to do that? My concern is when it hits the destructor that it's not going to deallocate the memory in the list that vertex points to. The two list idea should get rid of that (I think) but it seems like a lot to make two separate list classes just to run on program. Any suggestions?