单链表节点的查找

                                单链表节点的查找
查找单链表pos位置的节点,返回节点指针
pos从0开始,0返回head节点
node *search_node(node *head,int pos)
{
node *p=head->next;
if(pos<0)
{
printf("incorrect position to search node! ");
return NULL;
}
if(pos==0)
{
return head;
}
if(p==NULL)
{
printf("Link is empty ");
return NULL;
}
while(--pos)
{
if((p=p->next)==NULL)
{
printf("incorrect position to search node ");
break;
}
}
return p;
}













原文地址:https://www.cnblogs.com/zhangaihua/p/3718074.html