回复 8楼 xzlxzlxzl
对了,还有个问题。您的add函数写的很巧妙,但我改了我的add函数,为什么还是不对呢?我感觉我的思路应该也能成功才对啊?下面是我改的add,希望能告诉我到底哪里写得不合适才会出错的?
程序代码:struct student *add(struct student*head,struct student *stu1)
{
struct student *p1,*p0,*p2;
p1=head;
p0=(struct student*)malloc(LEN);
p0=stu1;
p0->next=NULL;
if(head==NULL)
{
head=p0;
}
else
{
while ((p1!=NULL)&&(p0->num>p1->num))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num )
{
if(p1==head)
{
head=p0;
p0->next=p1;
}
else
{
p2->next=p0;
p0->next=p1;
}
}
else
{
p1->next=p0;
}
}
printf("\nDelete No: %d succeed!\n", p0->num);
n = n+1;
return(head);
}







