以下是使用 C 语言实现判断元素 `x` 是否在给定链表中的函数: ```c #include <stdio.h> #include <stdlib.h> typedef struct node { int elem; struct node *next; } node, *linklist; int searchInList(linklist l, int x) { node *p = l->next; int position = 1; while (p!= NULL) { if (p->elem == x) { return position; } p = p->next; position++; } return NULL; } int main() { // 初始化链表并进行测试 return 0; } ``` 在上述代码中,`searchInList` 函数从链表的第一个有效节点开始遍历,比较每个节点的值与目标值 `x` ,如果找到则返回位置,遍历完整个链表未找到则返回 `NULL` 。在 `main` 函数中您可以根据需要初始化链表并调用该函数进行测试。 [2024-09-25 13:42:10 | AI写代码神器 | 238点数解答]