This repository was archived by the owner on Nov 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.h
More file actions
58 lines (51 loc) · 1.31 KB
/
config.h
File metadata and controls
58 lines (51 loc) · 1.31 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
static int *init_asc(int len) {
int *a = malloc(len * sizeof(int));
for (int i = 0; i < len; ++i)
a[i] = i;
return a;
}
static int *init_des(int len) {
int *a = malloc(len * sizeof(int));
for (int i = 0; i < len; ++i)
a[i] = len-i-1;
return a;
}
#if RAND_MAX <= 32767
#warning "RAND_MAX is less than or equal to 32767."
#endif
static int *init_ran(int len) {
int *a = malloc(len * sizeof(int));
int c = RAND_MAX/len + 1; /* https://c-faq.com/lib/randrange.html */
for (int i = 0; i < len; ++i)
a[i] = rand() / c;
return a;
}
Metric sort_bubble(Sequence seq);
Metric sort_insert(Sequence seq);
Metric sort_quick(Sequence seq);
Metric sort_merge(Sequence seq);
Metric sort_heap(Sequence seq);
int repeattest = 3; /* repeat x times and get the average */
Sequence seqs[] = {
{"ascending", init_asc, 2000},
{"ascending", init_asc, 16000},
{"ascending", init_asc, 128000},
{"descending", init_des, 2000},
{"descending", init_des, 16000},
{"descending", init_des, 128000},
{"random", init_ran, 2000},
{"random", init_ran, 16000},
{"random", init_ran, 128000}
};
struct TestCase {
char *name;
SortFunc *sort;
Metric mets[LENGTH(seqs)];
};
TestCase tests[] = {
{"Bubble sort", sort_bubble},
{"Insertion sort", sort_insert},
{"Quicksort", sort_quick},
{"Mergesort", sort_merge},
{"Heapsort", sort_heap},
};