1 #include "stdafx.h"
2
3 #include "stdlib.h"
4 #include "string.h"
5 #include "stdio.h"
6
7 int cmp_i(const void *a, const void *b)
8 {
9 int res = *(int *)a - *(int *)b;
10 return res;
11 }
12 int cmp_s(const void *a, const void *b)
13 {
14 int res = strcmp((char *)a, (char *)b);
15 return res;
16 }
17
18 int main()
19 {
20 int values[] = {3,3546,6134,1,234,12435,51,3,4,32,3241,34514,5};
21 char strs[][15] = {"32","66","6134","1","234","12435","51","3","4","32","3241","34514","5"};
22
23 printf("-------------------\nQsort int\n");
24 for(int i=0;i<10;i++)
25 {
26 printf("%d\t",values[i]);
27 }
28 printf("\n");
29 qsort(values, 10, sizeof(int), cmp_i);
30 for(int i=0;i<10;i++)
31 {
32 printf("%d\t",values[i]);
33 }
34 printf("\n");
35
36 printf("-------------------\nQsort str\n");
37 for(int i=0;i<10;i++)
38 {
39 printf("%s\t",strs[i]);
40 }
41 printf("\n");
42 qsort(strs, 10, sizeof(char)*15, cmp_s);
43 for(int i=0;i<10;i++)
44 {
45 printf("%s\t",strs[i]);
46 }
47
48 }
49