Archived

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

mits

Linked Lists question

Recommended Posts

mits    122
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
Guest Anonymous Poster   
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