#include<stdio.h>
typedef struct LNode
{
int data;
int length ;
struct LNode *next;
}LNode,*LinkList;
int count = 0 ; //与length的相同
LNode * LocateElem(LinkList L,int e)
{
LinkList p=L;
p->length = 0 ;
while(p!=NULL&&p->data!=e)
{
int t = p->length ;
p=p->next;
if(p==NULL)
return p ;
p->length=t+1;
count++;
}
return p;
}
int main()
{
int n,i;
scanf("%d",&n);
LinkList p=new LNode;
LinkList L=p;
for(i=0;i<n;i++)
{
LinkList s=new LNode;
s->data=i;
p->next=s;
p=s;
}
p->next=NULL;
L=LocateElem(L,3);
if(L==NULL)
printf("该值找不到\n");
else
{
printf("%d\n",L->data);
printf("%d\n",L->length);
printf("%d\n",count);
}
return 0;
}
转载于:https://www.cnblogs.com/NYNU-ACM/p/4237356.html