Advertisement

Linked Lists

Started by March 08, 2001 07:41 AM
2 comments, last by JeJu 23 years, 10 months ago
Hello I have a problem with link lists. This is my code to initialize the LLs. for(f=b;f;f=f->next) { Now it loops until I break with some condition } The result looks like this ??!f!?? f = f->next f=f->next->next etc. Now at the end of the loop f has the value f->next.... .What I want to ask is how can i get it to store only the first ??!f!?? in another variable? Cheers Jens Jung
The iterator in your for loop sets f to f->next

Why would you initialize a linked list that is already created?

Whenever you add a node, set its next to NULL. When you create the list, set its head to NULL.

  class node{public:  data *d;  node *next;  node():next(NULL),d(NULL){}};class list{public:  node *head;  list():head(NULL){}}  


There are prolly some tutorials on linked lists on this site.
Or just use the STL list template and save yourself some time.
Advertisement
Mmmmm...not absoultely sure what you''re trying to accomplish. Whats wrong with just saying

  data x = b->info;  


?
quote:
Original post by Big B

There are prolly some tutorials on linked lists on this site.
Or just use the STL list template and save yourself some time.




Yup, here: http://www.gamedev.net/reference/programming/features/uds1/default.asp.

Kevin

Admin for GameDev.net.

This topic is closed to new replies.

Advertisement