Home > Back-end >  To a certain position in the chain list insert an element, and then wrote the following function to
To a certain position in the chain list insert an element, and then wrote the following function to

Time:03-26

Linklist * find (linklist * head, int I)
{
Linklist * p;
p=head;
int j=1;
while(p!=NULL& & j<=I)
{
j++;
P=p - & gt; next;
}
if(! P)
Printf (" p=NULL ");
The else
return p;

}

CodePudding user response:

 linklist * find (linklist * head, int I) 
{
Linklist * p;
p=head;
int j=1;
while(p!=NULL& & j<=I)
{
j++;
P=p - & gt; next;
}
if(! P) {
Printf (" p=NULL ");
return NULL;
}
//else
return p;

}

For your reference ~

Should be return NULL if not found

CodePudding user response:

Reference:
 linklist * find (linklist * head, int I) 
{
Linklist * p;
If (I==0) return the head;//if the header, return head node
p=head;
int j=0;
while(p!=NULL & amp; & j{
j++;
P=p - & gt; next;
}
if(! P) return NULL:
return p;
}
  • Related