struct student *add(struct student*head,struct student *stu1)
{
struct student *p1,*p0,*p2;
p1=head;
//p0=(struct student*)malloc(LEN);
p0=stu1;
if(p0->num==0) return head;
//这里我加上一句
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);
}
int main()
{
struct student *q,*stu,stu2,*p;
int x;
int a;
stu=creat();
q=stu;
//p=&stu2;
print(q);
printf("How do you want to do:del='1',add='2'\n");
scanf("%d",&a);
if(a==1)
{
do
{
printf("please input the num of you want to deleat: ");
scanf("%d",&x);
q=del(q,x);
if(q==NULL)
{
break;
}
print(q);
}while(x!=0);
}
else
{
do
{
p=(struct student*)malloc(LEN);
printf("\nplease input the num
you want to insert: ");
scanf("%d",&(p->num));
printf("please input the score
you want to insert: ");
scanf("%f",&(p->score));
q=add(q,p);
if(q==NULL)
{
break;
}
print(q);
}while(
p->num!=0);
}
printf("\n\n");
system("pause");
}