回调函数的使用
作者:互联网
#include <stdio.h>
int callBackCompare(int a,int b)
{
return a<b?0:1;
}
void selectSort(int *p, int n,int(*pf)(int,int))
{
for(int i=0; i<n-1 ;i ++)
{
for(int j=i+1; j<n; j++)
{
if(pf(p[i],p[j]))
{
p[i] = p[i]^p[j];
p[j] = p[i]^p[j];
p[i] = p[i]^p[j];
}
}
}
}
int main(void)
{
int arr[10] = {6,5,4,3,2,1,7,8,9,0};
selectSort(arr,10,callBackCompare);
for(int i=0; i<10; i++)
{
printf("%d\n",arr[i]);
}
return 0;
}
标签:callBackCompare,arr,return,函数,selectSort,10,int,使用,回调 来源: https://blog.csdn.net/weixin_44715313/article/details/116448403