给定程序中,函数fun的功能是统计出带有头结点的单向链表中结点的个数,存放在形参 n 所指的存储单元中。
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct list{
int data;
struct list *next;
} SLIST;
SLIST *creatlist(int *a);
void outlist(SLIST*);
void fun(SLIST *h,int *n){
SLIST *p;
/**********found**********/
*n=0;
p=h->next;
while(p){
(*n)++;
/**********found**********/
p=p->next;
}
}
void main(){
SLIST *head;
int a[N]={12,87,45,32,91,16,20,48},num;
head=creatlist(a);
outlist(head);
/**********found**********/
fun(head, &num);
printf("number=%d",num);
}
SLIST *creatlist(int a[]){
<