Function name : qsort
Header file : <stdlib.h>
Function prototype : void *qsort(void* district,size_t n,size_t m,
int (*fc)(const void*,const void*));
Function : Used to quickly sort records from small to large
Parameters : void* district points to the starting address of the area to be sorted
size_t n The number of elements in the area to be sorted
size_t m The size of each element in the area to be sorted
int (*fc)(const void*,const void*) A function pointer that compares the size of two elements
Return value : No return value
Program example : Use this function to quickly sort the unordered sequence arr.
#include<stdio.h>#include<stdlib.h>typedefint(*fc)(constvoid*,constvoid*);intcompare(constvoid*p1,constvoid*p2){return(*(int*)p1)-(* (int*)p2);}intma in(void){inti,arr[10]={1,6,5,7,8,9,11,24,3,10};fcf=compare;qsort(arr,10,sizeof(int),f );for(i=0;i<10;i++){printf(%dt,arr[i]);}putchar('n');return0;}
Running results
1356789101124