首页 > 代码库 > 函数指针

函数指针

排序函数qsort

 1 #include <stdio.h> 2  3 int compare (const void * a, const void * b) 4 { 5     return *(int *)a - *(int *)b; 6 } 7 int main (void) 8 { 9     int arr[15] = {999, 23, 39, 23, 199, 1, 23, -432, 1, 0, 23, -32, 235, 13, 2};10 11     int i;12     for (i = 0; i < 15; i++)13     {14         printf ("%5d ", arr[i]);15     }16     printf ("\n");17 18     qsort (arr, 15, sizeof (int), compare);19 20     for (i = 0; i < 15; i++)21     {22         printf ("%5d ", arr[i]);23     }24     printf ("\n");25 }

 

函数指针