关于链表的查找函数
话不多说先上码
程序代码:struct node * search(struct node *head , int num , int a) //head是头,num是要找的数 , a用来做标记
{
struct node *p , *q;
q = (struct node *)malloc(sizeof(struct node));
p = head;
q->next = p;
while(p)
{
if( p->data = num )
{
if( a == 0 )
{
return p;
}
else if( a == 1 )
{
printf("<<<<<<<<%d<<" , q->data);
return q;
printf(">>>>>>>>");
}
}
else
{
p = p->next;
q = q->next;
}
}
// return NULL;
while(q)
{
printf("\n%d\n" , q->data);
q = q->next;
}
}是在查找的时候随便可以找他的前一个结点,之前写的时候实现了,后来不小心把代码删了,又写不出来来了,哎;
为什么返回q不行啊(但是后面的while循环可以输出q啊);


