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

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; }