Reference: https://www.cnblogs.com/ForeverJoker/archive/2013/05/25/qsort-sort.html
Included in <stdlib.h>
Int (*CMP) (const void *,const void *);
Qsort (*s, N, sizeof (s[0]), CMP);
Contains 4 parameters, the first incoming position, the second sort amount, the third individual size, and the fourth sort method
Sorting an array
int type :
< Span class= "hljs-reserved" > int CMP ( const void *a, const void *b) {
< Span class= "hljs-reserved" >< Span class= "Hljs-keyword" > return * (int*) A-* (int*) b; < Span class= "hljs-reserved" >< Span class= "Hljs-keyword" >< Span class= "Hljs-keyword" >//from small to large sort
return * (int *) b-* (int *) A; Sort from large to small}
The return value of the CMP function, <0 (no permutation), >0 (for displacement), 0 (no permutation).
Double type:
INT cmp (const void * A, const void * b) {
< Span class= "hljs-reserved" >< Span class= "Hljs-keyword" > Return ((* (* (double*) A-* (double*) b> 0)? 1:-< span class= "Hljs-number" >1);}
< Span class= "hljs-reserved" >< Span class= "Hljs-keyword" >< Span class= "Hljs-keyword" >char:
< Span class= "hljs-reserved" >< Span class= "Hljs-keyword" >< Span class= "Hljs-keyword" > Return (* (char *) A-* (char *) b)
< Span class= "hljs-reserved" >< Span class= "Hljs-keyword" >< Span class= "Hljs-keyword" >struct type:
< Span class= "hljs-reserved" >< Span class= "Hljs-keyword" >< Span class= "Hljs-keyword" > TBD
< Span class= "hljs-reserved" >< Span class= "Hljs-keyword" >< Span class= "Hljs-keyword" >char s[][] Type:
< Span class= "hljs-reserved" >< Span class= "Hljs-keyword" >< Span class= "Hljs-keyword" > int cmp (const void *a, const void *b) {
< Span class= "Hljs-keyword" >< Span class= "Hljs-keyword" >< Span class= "Hljs-number" > return (strcmp ((char*) A, (char*) b)); }
Qsort Inductive Learning (C language version)