I am trying to figure out how I would make a linked list that contains other linked lists as the nodes. I am very new to linked lists, but I think I am beginning to understand them better, but this really confuses me.
I didn't think the lists had names because the tutorials just start with something like: (I am needing to use doubly linked lists if that matters)
1 2 3 4 5 6
|
struct node
{
string str;
node *prv = NULL;
node *nxt = NULL;
};
|
I thought that this was just to tell the program what a node was, but now I'm thinking this is how I would name a list, so if I did:
1 2 3 4 5 6
|
struct word
{
string str;
word *prv = NULL;
word *nxt = NULL;
};
|
Would that mean that I would have a list named word? So if I did this, then made another one with "lines" instead of "word", I would then have the beginnings of two linked lists?
If so, how would I make the second one to hold linked lists instead of strings? Would I just put a pointer to the other lists head?
If not, then how would I do this?
I am having to write a program that will read string data from a file. It is supposed to store each word in a line as a node in a list, then I am supposed to store each of those lists in a list that contains the lines. I also have to remove the symbols from the lines.
So if these are the lines:
xyz abc
fun sad book 123,678+1000
a AA aaa123, $%
[X]
Then "xyz" and "abc" would be nodes in one list, "fun", "sad", "book", "123", "678", and "1000" would be nodes in another list, and so on. Then I would need to have a list where each of those lists is a node.
So the other problem I have is that I won't know the exact number of lines or the number of words in a line, so how would I deal with that? How would I make it create lists for each line when I don't know how many there will be?
Sorry if I'm asking way too many questions, but I'm not that good at coding yet and I had never even heard of linked lists until a couple of days ago and this is really stressing me out.
I have looked online for help a lot before posting this and I will continue to look it up while I wait for an answer, so please don't tell me to go look it up.
Thanks in advance!
EDIT: I forgot to mention that I can't use the linked list template in the STL library.
EDIT: I just got done making a LinkedList class that works. So far it has a insert function and a print function. I'm thinking that this is how I am supposed to create different linked lists with names I can reference. I am still not sure how to do a linked list of linked lists though. My current class just has this for the node:
1 2 3 4 5 6 7 8 9 10 11 12
|
struct node
{
string str;
node *nxt = NULL;
node *prv = NULL;
node(string s)
{
str = s;
nxt=prv=NULL;
}
};
|
I'm also not sure how to use this class when I don't know the total number of lines. I could create an instance for each line, but I don't know how many to create.