7-3 两个有序链表序列的交集(20 分)有个点过不了

#include
struct Node{
int num;
struct Node *next;
};

struct Node *read();
void comp(struct Node *n,struct Node *m);
int main(){
struct Node *a,*b;
a=read();
b=read();
comp(a,b);
}
struct Node *read(){
int flag=1;
struct Node *head,*a,*b;
a=head=malloc(sizeof(struct Node));
head->next=NULL;
scanf("%d",&a->num);
if(a->num == -1) head=NULL;
while(a->num != -1){
if(flag != 1){
b=malloc(sizeof(struct Node));
b->next=NULL;
a->next=b;
a=b;
scanf("%d",&a->num);
}

else
flag = 0;

}
return head;

}
void comp(struct Node *n,struct Node *m){
int flag=1;
struct Node *a,*b,*n_head,*c;
if(n !=NULL && m != NULL)
while(n->num != -1 || m->num != -1)
{

if(n->num == m->num)
{
if(flag==1)
{
n_head=n;
n=n->next;
a=n_head;
flag=0;

}
else{
a->next=n;
a=n;
n=n->next;

a->next = NULL;

}
m=m->next;
}
else if(n->num == -1 || m->num == -1)
break;
else if(n->num < m->num)
n=n->next;
else if(n->num > m->num)
m=m->next;

}
else
{
printf("NULL");
return 0;
}

b=n_head;

while(b)
{
if(b->num == -1){printf("NULL");break;}
printf("%d",b->num);
if(b->next != NULL)
printf(" ");
b=b->next;
}

}
图片说明
当没有交集,输出NULL,为什么不给过呢。
图片说明

http://blog.csdn.net/chan_yeol/article/details/50990825