提取两个列表的公共元素失败

该函数取出列表A和B的公共元素,并插入到新形成的列表C中。但是该函数运行不正常。 即使没有显示任何错误,也无法获得预期的结果。

void mergeLL(struct node*A,struct node*B,struct node**C)
{
    struct node *t1=NULL,*t2=NULL,*temp=NULL;
    temp= (struct node *)malloc(sizeof(struct node));
    t1=A;
    while (t1->link!=NULL)
    {   t2=B;
        while(t2->link!=NULL)
        {
            if(t1->data==t2->data)
            {
                temp->data=t2->data;
                temp->link=(struct node *)malloc(sizeof(struct node));
                temp=temp->link;
                break;

            }
            t2=t2->link;
        }
        t1=t1->link;
    }
    *C=temp;
}
yonghengwupan 回答:提取两个列表的公共元素失败

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/5185.html

大家都在问