一个调用函数无法执行
void inter (struct stu *& head)
{
struct stu * p1, * p2, * p3;
p1 = (struct stu *)malloc(sizeof (struct stu));
printf("enter a NO;\n");
scanf ("%d", &p1->NO);
getchar ();
printf("enter a name:\n");
gets (p1->name);
printf ("enter a sex:\n");
scanf("%c", &p1->sex);
getchar ();
printf ("enter a score:\n");
scanf("%f", &p1->score);
p2 = head;
if (head == NULL)
{
head = p1;
}
while (p1->NO > p2->NO && p2 != NULL)
{
p3 = p2;
p2 = p2->next;
}
while (p1->NO < p2->NO || p2 == NULL)
{
if(p2 == head)
{
p1->next = head;
head = p1;
}
else
{
p1->next = p2;
p3->next = p1;
}
break;
}
}
如上,一个链表插入的主程序无法运行只能插入到表中位置和表头,表位插入老是结束进程。求大神帮忙看下。