• Advertisement

Archived

This topic is now archived and is closed to further replies.

Linked Lists question

This topic is 5459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I use this structure: struct Thing { int ID,value; char *name; Thing *next; }; I also made a search function: Thing *Find(int searchID) { //for(current=head;current;current=current->next) current=head; while(current) { if(current->ID==searchID) { return current; } current=current->next; } return NULL; } and in the main function I use it like that: Thing *thing1=NULL; thing1=Find(2); if(thing1) { cout << thing1->value ; } But the result is always 0.I can''t find what''s wrong , please help me. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Maybe you''re not properly initializing head.

Do this to see what''s happening:

  
current=head;
while(current)
{
cout << current->ID << endl;
if(current->ID==searchID)
...

Share this post


Link to post
Share on other sites

  • Advertisement