Napisałem listę dowiązaniową która ma następujące składowe
class Lista{
string id;//identyfikator
double value;
Lista*next;
....
do listy dodaję 3 elementy metodą
void Lista::add(Lista &nowy)
{
if(next==NULL)
next=&nowy;
else{
Lista*temp=this;
while(temp->next!=NULL)
temp=temp->next;
temp->next=&nowy;
}
}
Kiedy próbuję wyszukać (poniższą metodą) element po id,którego to elementu nie ma na liście, lista jakby robiła się cykliczna ponieważ program cały czas siedzi w pętli while i przeskakuje kolejno po 1,2 i trzecim elemencie (wyświetlałem sobie ich id).
edit: właściwa funkcja
bool Lista::isDefined(string ident)
{
if(next->id!=ident){
Lista *temp=next;
while( temp->id!=ident && temp->next!=NULL){
temp=temp->next;
cout<<endl<<"id "<<temp->id;
}
if(temp!=NULL && temp->id==ident)
return true;
else
return false;
}
else
return true;
}
Wie ktoś może dlaczego tak się dzieje?