2010C语言实验报告参考答案 下载本文

{

printf(\

printf(\printf(\printf(\printf(\

|\\n\

printf(\} }

STUDENT *insert(STUDENT *h) {

STUDENT *p,*q,*info; char s[11]; int s1,i;

printf(\scanf(\

printf(\

info=(STUDENT *)malloc(sizeof(STUDENT)); if(!info) {

printf(\return NULL; }

inputs(\

inputs(\printf(\s1=0;

for(i=0;i

printf(\if(i==1)

printf(\scanf(\

if(info->score[i]>100||info->score[i]<0) printf(\

}while(info->score[i]>100||info->score[i]<0); s1=s1+info->score[i]; }

info->sum=s1; info->order=0;

=

info->next=NULL; p=h; q=h;

while(strcmp(p->no,s)&&p!=NULL) { q=p;

p=p->next; }

if(p==NULL) if(p==h) h=info; else

q->next=info; else if(p==h) {

info->next=p; h=info; } else {

info->next=p; q->next=info; }

printf(\return(h); }

/* SAVE*/

void save(STUDENT *h) {

FILE *fp;

STUDENT *p; char outfile[10];

printf(\scanf(\

if((fp=fopen(outfile,\{

printf(\exit(1); }

printf(\p=h;

while(p!=NULL) {

fwrite(p,sizeof(STUDENT),1,fp); p=p->next; }

fclose(fp);

printf(\}

STUDENT *load() {

STUDENT *p,*q,*h=NULL; FILE *fp;

char infile[10];

printf(\if((fp=fopen(infile,\{

printf(\exit(1); }

printf(\

p=(STUDENT *)malloc(sizeof(STUDENT)); if(!p) {

printf(\return h; } h=p;

while(!feof(fp)) {

if(1!=fread(p,sizeof(STUDENT),1,fp)) break;

p->next=(STUDENT *)malloc(sizeof(STUDENT)); if(!p->next) {

printf(\return h; } q=p;

p=p->next; }

q->next=NULL; fclose(fp);

printf(\return h; }

/*sort*/

STUDENT *sort(STUDENT *h) {

int i=0;

STUDENT *p,*q,*t,*h1; h1=h->next; h->next=NULL; while(h1!=NULL) { t=h1;

h1=h1->next; p=h; q=h;

while(t->sumsum&&p!=NULL) { q=p;

p=p->next; }

if(p==q) {

t->next=p; h=t; } else {

t->next=p; q->next=t; } } p=h;

while(p!=NULL) { i++;

p->order=i; p=p->next; }

printf(\return h; }

/*index by number*/

STUDENT *index(STUDENT *h) {

STUDENT *p,*q,*t,*h1; h1=h->next;

h->next=NULL; while(h1!=NULL) {

t=h1;

h1=h1->next; p=h; q=h;

while(strcmp(t->no,p->no)>0&&p!=NULL) {

q=p;

p=p->next; }

if(p==q) {

t->next=p; h=t; } else {

t->next=p; q->next=t; } }

printf(\ return h; }??