6.3w+
社区成员
#include<stdio.h>
typedef struct ode
{
int value;
struct Node *link;
}Node;
/*Call back function, it's useful for different kind of node, we just want to change compare function*/
Node* getnode(Node *ele,void const *val, int (*compare)(void const*, void const *))
{
while(ele!=NULL)
{
if(compare(&(ele->value),val))
break;
ele=ele->link;
}
return ele;
}
int com_int(void const *a,void const *b)
{
if(*(int *)a==*(int *)b)
return 0;
else
return 1;
}
int main()
{
Node root;
Node one;
int target=90;
one.value=90;
one.link=NULL;
root.value=35;
root.link=&one;
Node* tmp=getnode(&root,&target,com_int);
if(tmp!=NULL)
{
printf("%d",tmp->value);
}
return 0;
}
//C和指针里面的一个例子,昨晚刚贴完。再贴一下吧。