2 u013429409 u013429409 于 2014.03.18 13:39 提问

为什么两个查找i和item的返回值p的地址输出都是一样的?

int LocItem1(linklist *L,int n,int i){
linklist *q,*p;
int j=0;
if(L->next==NULL)
{
printf("The linklist is empty\n");
return NULL;
}
else if(i>n)
{
printf("i>n is beyound\n");
return NULL;
}
else
{
q=L;
p=L->next;
while(p!=NULL&&j {
q=p;
p=p->next;
j++;
}
}
if(p==NULL)
{
printf("The node %d is not exist\n",i);
return NULL;
}
else
return p;
}
int LocItem2(linklist *L,int n,int item){
linklist *p,*q;
if(L->next==NULL)
{
printf("The linklist is empty\n");
return NULL;
}
else
{
q=L;
p=L->next;
while(p!=NULL)
{
if(p->data!=item)
{
q=p;
p=p->next;
}
else
break;
}
}
if(p==NULL)
{
printf("The node %d is not exist\n",item);
return NULL;
}
else
return p;
}
int main()
{
int n,i,item;
long int k;
linklist *L;
L=Creatlist(L);
Judge(L);
printf("Input nodes :");
scanf("%d",&n);
Input(L,n);
printf("Input i:");
scanf("%d",&i);
k=LocItem1(L,n,i);
printf("The i %d address is %ld\n",i,k);
printf("Input item:");
scanf("%d",&item);
k=LocItem2(L,n,item);
printf("The item %d address is %ld\n",item,k);
return 0;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!