链表看不懂啊
#include <stdio.h>#include <stdlib.h>
#define N 8
struct slist
{ double s;
struct slist *next;
};
typedef struct slist STREC;
double fun( STREC *h )
{
int i;
}
STREC * creat( double *s)
{ STREC *h,*p,*q; int i=0;
h=p=(STREC*)malloc(sizeof(STREC));p->s=0;
while(i<N)
{ q=(STREC*)malloc(sizeof(STREC));
q->s=s[i]; i++; p->next=q; p=q; 就这句,书上的解释很抽象,看不懂
}
p->next=0; 这句也不怎么明白
return h;
}
outlist( STREC *h)
{ STREC *p;
p=h->next; printf("head");
do
{ printf("->%4.1f",p->s);p=p->next;}
while(p!=0);
printf("\n\n");
}
main()
{ double s[N]={85,76,69,85,91,72,64,87},ave;
void NONO ( );
STREC *h;
h=creat( s ); outlist(h);
ave=fun( h );
printf("ave= %6.3f\n",ave);
NONO();
}
void NONO()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *in, *out ;
int i,j ; double s[N],ave;
STREC *h ;
in = fopen("in.dat","r") ;
out = fopen("out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
for(j=0 ; j < N; j++) fscanf(in, "%lf,", &s[j]) ;
h=creat( s );
ave=fun( h );
fprintf(out, "%6.3lf\n", ave) ;
}
fclose(in) ;
fclose(out) ;
}