Skip to content
This repository was archived by the owner on Nov 3, 2024. It is now read-only.

Commit a42dc10

Browse files
committed
Add README.txt and commentary
1 parent 186318a commit a42dc10

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

README.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Compile using GNU Make:
2+
$ make
3+
4+
And run:
5+
$ ./test
6+
7+
Configurable variables are present in config.h

config.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ static int *init_des(int len) {
1616
#warning "RAND_MAX is less than or equal to 32767."
1717
#endif
1818
static int *init_ran(int len) {
19-
int *a = malloc(len * sizeof(int)), c = RAND_MAX/len + 1;
19+
int *a = malloc(len * sizeof(int));
20+
int c = RAND_MAX/len + 1; /* https://c-faq.com/lib/randrange.html */
2021
for (int i = 0; i < len; ++i)
2122
a[i] = rand() / c;
2223
return a;
@@ -28,7 +29,7 @@ Metric sort_quick(Sequence seq);
2829
Metric sort_merge(Sequence seq);
2930
Metric sort_heap(Sequence seq);
3031

31-
int repeattest = 3; /* repeat x times and get the average */
32+
int repeattest = 3; /* repeat x times and get the average */
3233

3334
Sequence seqs[] = {
3435
{"ascending", init_asc, 2000},

sorts/quick.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ static void quicksort(int *a, int len) {
99
int i, j, t;
1010
for (i = 0, j = len - 1; ; ++i, --j) {
1111
if (a[i] < pivot) {
12-
do {
12+
do {
1313
++i;
1414
++M.comp;
1515
} while (a[i] < pivot);
1616
}
1717
++M.comp;
1818
if (a[j] > pivot) {
19-
do {
19+
do {
2020
--j;
2121
++M.comp;
2222
} while (a[j] > pivot);

test.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ typedef struct Sequence Sequence;
44

55
typedef struct {
66
unsigned long long comp, swap; /* comparisons, swaps, */
7-
double ptime; /* CPU time (in ms) */
7+
double ptime; /* CPU time (in ms) */
88
} Metric;
99

1010
struct Sequence {

0 commit comments

Comments
 (0)