|
Simply Linked Lists...
Hey, I have a few questions on this simply linked list below. I''m just now trying to understand them with a book/tutorial, yet there is a few things that baffle me. =(
1. Why does root set the next node to NULL in "root->next=NULL". Wouldn''t this make the while loop below it never run if the next node is always at NULL.
2. Even if the while loop started, how would it ever stop? I don''t see how the next pointer would ever be NULL. In the last portion of code, he creates one more node to add on and sets that to NULL to make that the end, but this is after the while loops ends.
3. Also, if the while loop ends on a NULL pointer, then why add another node with a pointer to NULL after it?
4. If anyone has any tips/tutorials/websites or anything that you think is very explanational(is that a word?) on simply linked list, would you mind sending them my way. I understand the basic concept, but as far as putting it togther, I am lost.
Thanks for your help, heres the code btw :
1. It is set as NULL because there is no ''next'' node in the list, and because you don''t want to just leave the variable uninitialised.
Yes, it would make the while loop never run. But I think the author''s point is, if there were more nodes, it would run.
2. The while loop will stop when the end of the list is reached, because the last node in the list will be NULL (see above). The code to create another node isn''t in the while loop.
3. If you wanted to add an item to the end of the list, you would have to first find the end. That''s what the while loop does. A node is added to the end once it is found.
4. Uh ... I don''t know. I''m sure there are some good articles on it in GameDev''s reference section.
~~~~~~~~~~
Martee
Yes, it would make the while loop never run. But I think the author''s point is, if there were more nodes, it would run.
2. The while loop will stop when the end of the list is reached, because the last node in the list will be NULL (see above). The code to create another node isn''t in the while loop.
3. If you wanted to add an item to the end of the list, you would have to first find the end. That''s what the while loop does. A node is added to the end once it is found.
4. Uh ... I don''t know. I''m sure there are some good articles on it in GameDev''s reference section.
~~~~~~~~~~
Martee
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement