用算法实现有一个单链表其头指针为head,编写一个函数计算域为x的结点个数。

来源:百度知道 编辑:UC知道 时间:2024/04/29 04:51:19
用算法实现有一个单链表(不同结点的数据域值可能相同),其头指针为head,编写一个函数计算域为x的结点个数。

很久没有写拉,不知道是可以编译通过,不过基本就是这个样子!
int count(* head)
{
int sum=0;
struct yourds *temp;
if(!head)return;
*temp=head->next;
while(temp)
{
if(temp->data==x)
sum++;
*temp=temp->next;
}
return sum;
}