I am trying to write a function to
find(x) -- Searches through the list for the value x and returns an Iterator pointing to the first node containing value x. If x is not found in the list, it returns an Iterator pointing to NULL. ( I want to use linear search that starts from one end and checks each element one by one.
so I wrote this code:
[CODE=cpp]//find function
template<typena me T>
void LinkedList<T>:: find(T value)
{
Node<T>* pos=first;
while(pos){
if (pos.get()==val ue){
return pos;
}
else{
pos=pos->next;
}
}
return pos=NULL;
}[/CODE]
so now lets say in the main part we have
iter2 = rebelList2.find ("book");
but my code dosent work
would you help me?
thanks
find(x) -- Searches through the list for the value x and returns an Iterator pointing to the first node containing value x. If x is not found in the list, it returns an Iterator pointing to NULL. ( I want to use linear search that starts from one end and checks each element one by one.
so I wrote this code:
[CODE=cpp]//find function
template<typena me T>
void LinkedList<T>:: find(T value)
{
Node<T>* pos=first;
while(pos){
if (pos.get()==val ue){
return pos;
}
else{
pos=pos->next;
}
}
return pos=NULL;
}[/CODE]
so now lets say in the main part we have
iter2 = rebelList2.find ("book");
but my code dosent work
would you help me?
thanks
Comment