该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
#define LEN sizeof(struct student)
struct student
{
int num;
float score;
struct student *next;
};
int n,m;
struct student *creat()
{
struct student *p1,*p2,*head;
p2=p1=(struct student*)malloc(LEN);
scanf("%d",&p1->num);
scanf("%f",&p1->score);
head=NULL;
m=n=0;
while(p1->num)
{
n++;
m++;
if(n==1)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%d",&p1->num);
scanf("%f",&p1->score);
}
p2->next=NULL;
return head;
}
void print(struct student *head)
{
struct student *p;
p=head;
while(n--)
{
printf("%d\n",p->num);
printf("%f\n",p->score);
p=p->next;
}
}
struct student *del(struct student *head,int num)
{
struct student *p1,*p2;
p1=head;
while(p1->next!=NULL && num!=p1->num)
{
p2=p1;
p1=p1->next;
}
if(p1==head)
{
head=p1->next;
}
else
{
p2->next=p1->next;
}
return head;
}
struct student *add(struct student *head,int num1,float score1)
{
struct student *p1,*o3;
p1=head;
while(p1->next!=NULL)
{
p1=p1->next;
}
o3=(struct student*)malloc(LEN);
o3->num=num1;
o3->score=score1;
p1->next=o3;
o3->next=NULL;
return head;
}
void main()
{
int num,num1;
float score1;
struct student *stu,*stu1,*stu2;
stu1=creat();
print(stu1);
printf("have %d the num\n ",m);
printf("please enter the num:");
scanf("%d",&num);
stu=del(stu1,num);
print(stu);
printf("please enter the num1 and score1:");
scanf("%d",&num1);
scanf("%f",&score1);
stu2=add(stu1,num1,score1);
print(stu2);
system("pause");
}