科大C语言链表文件大作业

#include #include #include

#defineSTUDENTstruct student doubleaver,max; structstudent {

intnum;

float score;

structstudent* next; };

STUDENT* make(intn,floats) {

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; intn;float s; while(1) {

printf(\请输入学生的学号和成绩:\); scanf(\,&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; intn;float s; while(1) {

printf(\请输入学生的学号和成绩:\); scanf(\,&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; intn;float s; while(1) {

printf(\请输入学生的学号和成绩:\); scanf(\,&n,&s); if(n==0) break; p=make(n,s);

head=insert1(head,p); }

return(head); }

STUDENT *insert2(intn,STUDENT* p,STUDENT* head) {

STUDENT *q; inti; if(n==1) {

p->next=head; head=p; returnhead; }

for(q=head,i=1;q&&inext,i++) ; if(q) {

p->next=q->next; q->next=p; returnhead; } else

printf(\插入点位置过大,请修改插入位置:\); }

STUDENT *delect1(intn,STUDENT *head) {

STUDENT *p,*q; inti;

if(head==NULL) returnhead; 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); } }

returnhead; }

STUDENT *delect2(STUDENT *head,intnum) {

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;

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4