这个程序怎么运行的
Node * Add(Node *a, Node *b){
Node *p, *q, *pre,*head;
head=(Node*)malloc(sizeof(Node));
p = a; q = b;
pre = head;
pre->next=pre;
while (p != NULL&&q != NULL)
{
if (p->n < q->n)
{
pre=pre->next;
pre->next = (Node*)malloc(sizeof(Node));
pre->a=q->a ;
pre->n=q->n;
q=q->next;
}
else if (p->n == q->n)
{
pre=pre->next;
pre->next = (Node*)malloc(sizeof(Node));
pre->a=p->a + q->a ;
pre->n=q->n;
q=q->next;
p=p->next;
}
else
{
pre=pre->next;
pre->next = (Node*)malloc(sizeof(Node));
pre->a= p->a ;
pre->n=p->n;
p=p->next;
}
}
while(p||q)
{
if (p != NULL)
{
pre=pre->next;
pre->next = (Node*)malloc(sizeof(Node));
pre->a=p->a;
pre->n=p->n;
p=p->next;
}
else
{
pre=pre->next;
pre->next = (Node*)malloc(sizeof(Node));
pre->a=q->a;
pre->n=q->n;
q=q->next;
}
}
pre->next=NULL;
return head;