任何帮助都将有所帮助。我写了一个代码来查找两个链表的联合。但是,我正在一个部分获得无限循环。我在代码中指出它。请帮我找出错误。谢谢。两个链接列表的联合 - C++
//Finds the union of two linked lists.
nodeType* unionLL(nodeType *&headA, nodeType *&headB)
{
nodeType *tempA, *tempB, *newNode;
tempA = headA;
tempB = headB;
bool match = false;
while (tempB -> link != NULL)
{
while (tempA -> link != NULL)
{
outfile <<"The infinite loop occurs here " << endl;
if (tempB -> intVal == tempA -> intVal)
{
match = true;
}
tempA = tempA -> link;
}
if (!match)
{
newNode = new nodeType;
newNode -> intVal = tempB -> intVal;
newNode -> link = NULL;
tempA -> link = newNode;
}
tempA = headB;
tempB = tempB -> link;
}
return headB;
}
把它们放入std :: set怎么样? – xDD 2011-05-23 23:36:47
如果这是一个家庭作业问题,请阅读http://meta.stackexchange.com/questions/10811/how-to-ask-and-answer-homework-questions – MatrixFrog 2011-05-23 23:36:47
评论:'' - >''操作符绑定非常严格的逻辑;不要在代码两边都写空格......对于有经验的程序员来说看起来很奇怪。 – 2011-05-23 23:42:34