May 23, 2012 at 7:23pm
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 May 23, 2012 at 7:24pm
May 23, 2012 at 7:57pm
You have to make the first loop stop when it reach the end of the list.