69,369
社区成员
发帖
与我相关
我的任务
分享
// testprimer.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdlib.h>
typedef struct node
{
int a;
struct node * next;
}node;
typedef bool (* remove_fn)(node *v);
bool func(node *v)
{
(*v).a=(*v).a+1;
return(NULL==v);
}
node * remove_if(node * head, remove_fn rm)
{
for (node * prev = NULL, * curr = head; curr != NULL; )
{
node * const next = curr->next;
if(rm(curr))
{
if(prev)
prev->next=next;
else
head=next;
free(curr);
}
else
prev=next;
curr=next;
}
return head;
}
int _tmain(int argc, _TCHAR* argv[])
{
remove_fn rm=func;
node *x=NULL;
bool (*f)(node *v);
f=func;
node y;
y.a=0;
x=&y;
// *x=y;
if((*rm)(x)) printf("x==NULL y.a=%d\n",y.a );
else printf("x!=NULL y.a=%d\n",y.a);
if(f(x)) printf("x==NULL y.a=%d\n",y.a);
else printf("x!=NULL y.a=%d\n",y.a);
getchar();
return 0;
}