关于C语言链表的问题。

建立一个带有头节点的链表,在带头结点的链表head中查找元素x,若找到,则返回结点序号,否则返回0,并将查找操作写成函数完成。请问这个程序该怎么写?

http://www.jb51.net/article/55194.htm

首先,我们假设你要找的X是int类型,如果是其他类型操作也类似,
int serach(int x,Listnode *head)

int index=0;
listnode *pNode=head;
while(pNode->next)
{
if(pNode->data!=x)
{
pNode=pNode->next;
index++;
}
else
return index;
}
return -1;