-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqsort.h
More file actions
39 lines (33 loc) · 913 Bytes
/
qsort.h
File metadata and controls
39 lines (33 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <unistd.h>
#define qsort_log(fmt, ...) {fprintf(stdout, fmt, ##__VA_ARGS__); fflush(stdout);}
/* 打印数组 */
static inline void array_dump(int* list, int len) {
qsort_log("list = { ");
for (int index = 0; index < len; index ++){
qsort_log("%d", list[index]);
if (index + 1 != len)
qsort_log(", ");
}
qsort_log(" }\n");
}
/* 验证升序数组 */
static inline int asc_verify_sort(int* list, int len) {
for (int index = 0; index < len - 1; index ++) {
if (list[index] > list[index + 1])
return -1;
}
return 0;
}
/* 验证降序数组 */
static inline int desc_verify_sort(int* list, int len) {
for (int index = 0; index < len - 1; index ++) {
if (list[index] < list[index + 1])
return -1;
}
return 0;
}
void Qsort(int array[], int array_len, int (*cmp) (int, int));