need help in search item, link list

i need a search function that will search my each of my link list item and cout it, if item do not found, cout not found message...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.
.
.
void search(string item)
{
  current = head;
  while(current->info != item)
  {
    current = current->link;     //infinity loops occur when item not found
  }
  
  if(current->info == item)
    cout << current->info;
  else
   cout << "item not found";
}


when a not valid "item" is entered to this function, infinity loops happened, need help in fixing this code....
Last edited on
You have to make the first loop stop when it reach the end of the list.
ok i get it now! thx
Topic archived. No new replies allowed.