mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
28 lines
545 B
C
28 lines
545 B
C
// Copyright © 2018 ChaiShushan <chaishushan{AT}gmail.com>.
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define DIM(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
|
static int cmp(const void* a, const void* b) {
|
|
const int* pa = (int*)a;
|
|
const int* pb = (int*)b;
|
|
return *pa - *pb;
|
|
}
|
|
|
|
int main() {
|
|
int values[] = { 42, 8, 109, 97, 23, 25 };
|
|
int i;
|
|
|
|
qsort(values, DIM(values), sizeof(values[0]), cmp);
|
|
|
|
for(i = 0; i < DIM(values); i++) {
|
|
printf ("%d ",values[i]);
|
|
}
|
|
printf("\n");
|
|
|
|
return 0;
|
|
}
|