#include
#include
#include
#define STUDENT struct student
double aver,max;
struct student
{
int num;
float score;
struct student* next;
};
STUDENT* make(int n,float s)
{
STUDENT *p;
p=(STUDENT*)malloc(sizeof(STUDENT));
p->num=n;p->score=s;p->next=NULL;
return p;
}
STUDENT *create1(void)
{
STUDENT *head=NULL,*p,*q=NULL;
int n;float s;
while(1)
{
printf("请输入学生的学号和成绩:");
scanf("%d%f",&n,&s);
if(n==0)
break;
p=make(n,s);
if(head==NULL)
head=p;
else
q->next=p;
q=p;
}
if(q) q->next=NULL;
return head;
}
STUDENT *create2(void)
{
STUDENT *head=NULL,*p;
int n;float s;
while(1)
{
printf("请输入学生的学号和成绩:");
scanf("%d%f",&n,&s);
if(n==0)
break;
p=make(n,s);
p->next=head;head=p;
}
return head;
}
STUDENT* insert1(STUDENT*head,STUDENT*p)
{
STUDENT *q;
int n=p->num;
if(head==NULL||head->num>n)
{
p->next=head;
head=p;
return(head);
}
for(q=head;q->next&&q->next->numnext)
;
p->next=q->next;
q->next=p;
return(head);
}
STUDENT* create3(void)
{
STUDENT *head=NULL,*p;
int n;float s;
while(1)
{
printf("请输入学生的学号和成绩:");
scanf("%d%f",&n,&s);
if(n==0)
break;
p=make(n,s);
head=insert1(head,p);
}
return(head);
}
STUDENT *insert2(int n,STUDENT* p,STUDENT* head)
{
STUDENT *q;
int i;
if(n==1)
{
p->next=head;
head=p;
return head;
}
for(q=head,i=1;q&&inext,i++)
;
if(q)
{
p->next=q->next;
q->next=p;
return head;
}
else
printf("插入点位置过大,请修改插入位置:");
}
STUDENT *delect1(int n,STUDENT *head)
{
STUDENT *p,*q;
int i;
if(head==NULL) return head;
if(n==1)
{
p=head;
head=head->next;
free(p);
}
else
{
for(p=head,i=1;p->next&&inext)
;
if(p->next)
{
q=p->next;
p->next=q->next;
free(q);
}
}
return head;
}
STUDENT *delect2(STUDENT *head,int num)
{
STUDENT *q,*p;
for(p=head;p&&p->num!=num;q=p,p=p->next)
;
if(p==NULL)
printf("未找到\n");
else
{
if(p==head)
head=p->next;
else q->next=p->next;