一个把一个链表完全拷贝到另外一个链表的方程,请问那边出错了

来源:百度知道 编辑:UC知道 时间:2024/07/10 19:09:04
MailNode *copylist(MailNode *messageList)
{

MailNode *q, *r, *m,*temp;
temp=messageList;
q = (MailNode *)malloc(sizeof(MailNode));
if (q == NULL)
exit(1);
q->from = temp->from;
q->to = temp->to;
q->subject =temp->subject;
q->date = temp->date;
q->messageId = temp->messageId;
q->inReplyTo =tempt->inReplyTo;
q->content = temp->content;
q->status = temp->status;
q->priority =temp->priority;
q->msgNum =temp->msgNum;
// include all your struct value
m = q;
while (messageList->next != NULL)
{
r = (MailNode *)malloc(sizeof(MailNode));
if (r == NULL)
exit(1);
r->from = temp->from;
r->to = temp->to;
r->subject =temp->subject;
r->date = temp->date;
r->messageId = temp->messageId;

你的 q 和 r 内容完全一样哦

把while (messageList->next != NULL)改成while (temp != NULL)
并在前面加上temp=temp->next;
这样试试吧,我刚重装的系统,也没环境帮你运行下。