#include <stdio.h>
#include <stdlib.h>
#define N 5
typedef struct list
{
int data;
struct list *next;
}LNode;
LNode *creatlist(int *a)
{
LNode *h,*p,*q;
int i;
h=p=(LNode *)malloc(sizeof(LNode));
for(i=0; i<N; i++)
{
q=(LNode *)malloc(sizeof(LNode));
q->data=a[i];
p->next=q;
p=q;
}
p->next=0;
return h;
}
void outlist(LNode *h)
{
LNode *p;
p=h->next;
if (p==NULL)
printf("\nThe list is NULL!\n");
else
{
printf("\nHead");
do {
printf("->%d",p->data);
p=p->next;
} while(p!=NULL);
printf("->End\n");
}
}
int fun(LNode *h,int x)
{
LNode *p;
int count=0;
p=h->next;
while(p)
{
if(p->data==x)
{
count++;
}
p=p->next;
}
return count;
}
int main( )
{
LNode *A;
int a[N]={4,10,7,5,9};
A=creatlist(a);
printf("结点值为5的总个数为:%d",fun(A,5));
return 0;
}