2 u013566664 u013566664 于 2014.10.13 22:09 提问

链表循环打印崩溃问题

#include
#include
struct Grade_Info
{
int score;
struct Grade_Info *next;
};

typedef struct Grade_Info NODE;

NODE creat ( )

{
NODE *head, *tail, *pnew;
int score;
head = (NODE
)malloc (sizeof(NODE));

head->next = NULL;    /
tail = head;
printf ("input the score of students:\n");

while (1)

{
scanf ("%d", &score);

if (score < 0)

break;

pnew = (NODE *)malloc (sizeof(NODE));

pnew->score = score;
pnew->next = NULL;
tail->next = pnew;
tail = pnew;
}

return head;
}
NODE *samevalue(NODE *a,NODE *b,NODE *c)
{
NODE *pa,*pb,*pc;
pc=c;
pa=a->next;pb=b->next;
while(pa&&pb)
{
if(pa->score-pb->score pa=pa->next;
else if(pa->score-pb->score>0)
pb=pb->next;
else
{
c->next=pa;
c=c->next;
pa=pa->next;
pb=pb->next;

        }
    }
    c->next=NULL;

    return pc;

}

int main ()
{
NODE *a,*b,*c;
a=creat();
b=creat();
c=samevalue(a,b,c);
c=c->next;
while(c)
{printf("%d ",c->score);
c=c->next;
}

}
main里一个一个打印score就可以,用循环就崩溃,我都快崩溃了

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!