主题:很急很急
怎么改呢?
#include<malloc.h>
#include <stdio.h>
#include<string.h>
#define len sizeof(struct student)
#define NULL 0
struct student{
char num[20];
char name[20];
float score[3];
float zongfen;
struct student *next;
};
int count=0;
struct student * input();
struct student * inset(struct student *head,struct student *stu);
struct student * deleted(struct student *head,char *name);
void search(struct student *head,char *name);
struct student * paixu(struct student *head,int count);
struct student * jisuan(struct student *head);
int main(void)
{
struct student *head,*p;
char num[20];
char name[20];
int choice,i;
do{
printf("1:input() 2:inset() 3:deleted() 4:search() 5:paixu() 6:jisuan()");
printf("enter chioce:");
scanf("%d",&choice);
switch(choice){
case 1:
head=input();
break;
case 2:
printf("input num and name:");
scanf("%d%s",num,name);
p= (struct student * ) malloc(len);
strcpy(p->num,num);
strcpy(p->name,name);
printf("enter shuxu english cyuyan:");
for(i=0;i<3;i++)
scanf("%s",p->score[i]);
head=inset(head,p);
break;
case 3:
printf("input name:");
scanf("%s",name);
head=deleted(head,name);
break;
case 4:
printf("input name:");
scanf("%s",name);
search(head,name);
break;
case 5:
head=paixu(head,count);
break;
case 6:
head=jisuan(head);
break;
case 0:
break;
}
}while(choice!=0);
return 0;
}
struct student * input()
{struct student *head,*p1,*p2;
int i;
p1=p2=(struct student * ) malloc(len);
printf("enter num and name:");
scanf("%s%s",p1->num,p1->name);
printf("enter shuxu english cyuyan:");
for(i=0;i<3;i++)
scanf("%s",p1->score[i]);
head=NULL;
while(p1->num!=0){
count=count+1;
if(count==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=p2=(struct student * ) malloc(len);
printf("enter num and name:");
scanf("%s%s",p1->num,p1->name);
printf("enter shuxu english cyuyan:");
for(i=0;i<3;i++)
scanf("%s",p1->score[i]);}
p2->next=NULL;
return head;
}
struct student * insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL){
head=p0;
p0->next=NULL;}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next ;}
if(p0->num <=p1->num )
{
if(head==p1)
head=p0;
else
p2->next=p0;
p0->next=p1;}
else
{
p1->next =p0;
p0->next =NULL;}
count=count+1;
return (head);
}return 0;}
struct student * deleted(struct student *head,char *name)
{
struct student *p1,*p2;
if(head==NULL)
{
printf("not list");
return head;
}
p1=head;
while((name!=p1->name)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next ;}
if(name==p1->name )
{
if(head==p1)
head=p1->next;
else
p2->next=p1->next;
printf("deletr:%s\n",name);}
else
printf("%s not been found\n",name);
count=count-1;
return head;}
void search(struct student *head,char *name)
{
struct student *p1;char *p3;
p3=name;
int flag,i;
p1=head;
flag=1;
for(p1=head;p1;p1->next )
if(p1->name==p3)
{
flag=1;
break;
}
else
printf("not found");
if(flag)
{
printf("%s%20s\n",p1->num,p1->name);
for(i=0;i<3;i++)
printf("%f\n",p1->score[i]);
}}
struct student * paixu(struct student *head,int count)
{
void shuxuepx(struct student *head,int count);
void englishpx(struct student *head,int count);
void cyuyanpx(struct student *head,int count);
void zongfenpx(struct student *head,int count);
int choice;
do{
printf("1:shuxuepx 2:englishpx 3:cyuyanpx 4:zongfenpx 0:退出");
scanf("%d",&choice);
switch(choice){
case 1:
shuxuepx(struct student *head,int count);
break;
case 2:
englishpx(struct student *head,int count);
break;
case 3:
cyuyanpx(struct student *head,int count);
break;
case 4:
zongfenpx(struct student *head,int count);
break;
}while(choice!=0);
return 0;
#include<malloc.h>
#include <stdio.h>
#include<string.h>
#define len sizeof(struct student)
#define NULL 0
struct student{
char num[20];
char name[20];
float score[3];
float zongfen;
struct student *next;
};
int count=0;
struct student * input();
struct student * inset(struct student *head,struct student *stu);
struct student * deleted(struct student *head,char *name);
void search(struct student *head,char *name);
struct student * paixu(struct student *head,int count);
struct student * jisuan(struct student *head);
int main(void)
{
struct student *head,*p;
char num[20];
char name[20];
int choice,i;
do{
printf("1:input() 2:inset() 3:deleted() 4:search() 5:paixu() 6:jisuan()");
printf("enter chioce:");
scanf("%d",&choice);
switch(choice){
case 1:
head=input();
break;
case 2:
printf("input num and name:");
scanf("%d%s",num,name);
p= (struct student * ) malloc(len);
strcpy(p->num,num);
strcpy(p->name,name);
printf("enter shuxu english cyuyan:");
for(i=0;i<3;i++)
scanf("%s",p->score[i]);
head=inset(head,p);
break;
case 3:
printf("input name:");
scanf("%s",name);
head=deleted(head,name);
break;
case 4:
printf("input name:");
scanf("%s",name);
search(head,name);
break;
case 5:
head=paixu(head,count);
break;
case 6:
head=jisuan(head);
break;
case 0:
break;
}
}while(choice!=0);
return 0;
}
struct student * input()
{struct student *head,*p1,*p2;
int i;
p1=p2=(struct student * ) malloc(len);
printf("enter num and name:");
scanf("%s%s",p1->num,p1->name);
printf("enter shuxu english cyuyan:");
for(i=0;i<3;i++)
scanf("%s",p1->score[i]);
head=NULL;
while(p1->num!=0){
count=count+1;
if(count==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=p2=(struct student * ) malloc(len);
printf("enter num and name:");
scanf("%s%s",p1->num,p1->name);
printf("enter shuxu english cyuyan:");
for(i=0;i<3;i++)
scanf("%s",p1->score[i]);}
p2->next=NULL;
return head;
}
struct student * insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL){
head=p0;
p0->next=NULL;}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next ;}
if(p0->num <=p1->num )
{
if(head==p1)
head=p0;
else
p2->next=p0;
p0->next=p1;}
else
{
p1->next =p0;
p0->next =NULL;}
count=count+1;
return (head);
}return 0;}
struct student * deleted(struct student *head,char *name)
{
struct student *p1,*p2;
if(head==NULL)
{
printf("not list");
return head;
}
p1=head;
while((name!=p1->name)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next ;}
if(name==p1->name )
{
if(head==p1)
head=p1->next;
else
p2->next=p1->next;
printf("deletr:%s\n",name);}
else
printf("%s not been found\n",name);
count=count-1;
return head;}
void search(struct student *head,char *name)
{
struct student *p1;char *p3;
p3=name;
int flag,i;
p1=head;
flag=1;
for(p1=head;p1;p1->next )
if(p1->name==p3)
{
flag=1;
break;
}
else
printf("not found");
if(flag)
{
printf("%s%20s\n",p1->num,p1->name);
for(i=0;i<3;i++)
printf("%f\n",p1->score[i]);
}}
struct student * paixu(struct student *head,int count)
{
void shuxuepx(struct student *head,int count);
void englishpx(struct student *head,int count);
void cyuyanpx(struct student *head,int count);
void zongfenpx(struct student *head,int count);
int choice;
do{
printf("1:shuxuepx 2:englishpx 3:cyuyanpx 4:zongfenpx 0:退出");
scanf("%d",&choice);
switch(choice){
case 1:
shuxuepx(struct student *head,int count);
break;
case 2:
englishpx(struct student *head,int count);
break;
case 3:
cyuyanpx(struct student *head,int count);
break;
case 4:
zongfenpx(struct student *head,int count);
break;
}while(choice!=0);
return 0;