问题描述
- 为什么两个查找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 emptyn");
return NULL;
}
else if(i>n)
{
printf("i>n is beyoundn");
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 existn",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 emptyn");
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 existn",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 %ldn",i,k);
printf("Input item:");
scanf("%d",&item);
k=LocItem2(L,n,item);
printf("The item %d address is %ldn",item,k);
return 0;
}
时间: 2024-10-27 12:54:24