typedef struct node
{
int data;
struct node* next;
}LinkNode;
//取元素:取给定位置的元素值
//输入:链表的头指针,要查找的编号,
//输出第pos个元素的地址LinkNode* search_node(LinkNode*head, int pos)
{
LinkNode*p = head; //头结点对应下标为0
int j = 0;
if(pos==0)
{
retun NULL;
}
while(j<pos && p->next !=NULL)
{
p=p->next;
j++;
}
if(pos == j)
{
return p;
}
else
{
return NULL;
}}
//查元素:查找给定元素值的位置
///找到就返回节点的地址,找不到就返回NULLLinkNode* search_node(LinkNode*head, int data)
{
LinkNode* p = head->next; //跳过头结点
while(p != NULL && p->data != data)
{
p=p->next;
}
return p;
}
查找给定位置pos和或给定数据data的结点位置
于 2023-04-24 21:09:27 首次发布