hello,,:)
i have problem doing a FOR loop in my linked list,, it doesn't start the loop,, i don't know why...
class node
{
public:
node(int number, node*nxt):number(number),nxt(nxt){}
int getNumber(){return number;}
void setNumber(int number){this->number=number;}
node* getNxt(){return nxt;}
void setNxt(node *){this->nxt=nxt;}
private:
int number;
node *nxt;
};
bool mergeList(node *&result, node *list1, node *list2)
{
if(!result)
{
[B]for(node *i=list1, *j=list2; i->getNxt()!=NULL || j->getNxt()!=NULL;\
i=i->getNxt(), j=j->getNxt())
{
if(!result)
{
if(i->getNumber() <= j->getNumber())
{
result = i;
result->setNxt(j);
result = j;
result->setNxt(NULL);
}
else
{
result = j;
result->setNxt(i);
result = i;
result->setNxt(NULL);
}
}
else
{
if(i->getNumber() <= j->getNumber())
{
if(i->getNumber() <= result->getNumber())
return false;
else
{
result->setNxt(i);
result = i;
result->setNxt(j);
result = j;
result->setNxt(NULL);
}
}
else
{
if(j->getNumber() <= result->getNumber())
return false;
else
{
result->setNxt(j);
result = j;
result->setNxt(i);
result = i;
result->setNxt(NULL);
}
}
}
}[/B]
return true;
}
else
return false;
}
the loop doesn't run,, and i'm sure RESULT is empty when i passed it (function always return TRUE)...
thx...