#include <stdio.h> // 1.定义指针函数实现数组排序(百度)
void printArray(int *array, int len); // typedef 给数据类型起别名
typedef int (*Pointer)(int a,int b);
int compare(int a,int b) { return a < b; }
//函数指针作为参数,那个传入的函数是一个回调函数 void selectSort(int *array,int length,Pointer compare) {
for (int i = 0; i < length -1; i++) {
for (int j = i + 1; j < length; j++) {
if (array < array[j]) { int temp = array; array = array[j]; array[j] = temp; }
} } }
int main(int argc, const char * argv[]) { int nums[] = {10,8,6,11,12,3}; int length = sizeof(nums) / sizeof(int); printArray(nums, length); selectSort(nums, length,compare); printArray(nums, length);
typedef int Integer; Integer num = 10; printf("%d\n",num);
return 0; }
void printArray(int *array, int len) { for (int i = 0; i < len; i++) { printf("%d ",array); } printf("\n"); }
|