#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node
{int data
;
struct node
*next
;
}Node
;
int count(Node
* head
,int m
);
void destroy(Node
*p
);
int main(void)
{int n
,m
,x
;
Node
*head
=NULL,*s
,*tail
;
scanf("%d",&n
);
for(int i
=1;i
<=n
;i
++)
{scanf("%d",&x
);
s
=(Node
*)malloc(sizeof(Node
));
s
->data
=x
;
if(i
==1) head
=s
;
else tail
->next
=s
;
tail
=s
;
}
tail
->next
=NULL;
scanf("%d",&m
);
printf("%d\n",count(head
,m
));
destroy(head
);
system("PAUSE");
return 0;
}
int count(Node
* head
,int m
)
{ int k
=0;
Node
*p
=head
;
while(p
)
{if (p
->data
==m
)k
++;
p
=p
->next
;
}
return k
;
}
void destroy(Node
* head
)
{Node
*p
=head
,*q
;
while(p
)
{ q
=p
;
p
=p
->next
;
free(q
);
}
}
程序注解 P 348页
转载请注明原文地址:https://blackberry.8miu.com/read-32716.html