-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
85 lines (68 loc) · 1.77 KB
/
example.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright (c) 2015, Sky Leonard
All rights reserved.
For more info see COPYING or http://opensource.org/licenses/BSD-3-Clause
*/
#include <stdlib.h>
#include <time.h>
#include "partial.h"
#define NARRAYELEMENTS 24
static int array[NARRAYELEMENTS];
static void shuffle(){
int i;
int t;
size_t j;
for (i = 0; i < NARRAYELEMENTS - 1; ++i){
j = i + rand() / (RAND_MAX / (NARRAYELEMENTS - i) + 1);
t = array[j];
array[j] = array[i];
array[i] = t;
}
}
static void printarray(){
int i;
for (i = 0; i < NARRAYELEMENTS; ++i){
printf("%d ", array[i]);
}
puts("\n");
}
static int compar(int ud, int * a, int * b){
if (*a < *b)
return -ud;
else if (*a > *b)
return ud;
else
return 0;
}
int main(){
int i, res;
srand(time(NULL));
for (i = 0; i < NARRAYELEMENTS; ++i){
array[i] = i;
}
shuffle();
printarray();
res = partial_quick(
NULL, // return value (void)
"v pTT*", &qsort, // lib func
"i ipp", &compar, 1, // our func
array, NARRAYELEMENTS, sizeof(int), // qsort args
1); // compar args
if (res != 0){
return 1;
}
printarray();
shuffle();
printarray();
res = partial_quick(
NULL, // return value (void)
"v pTT*", &qsort, // lib func
"i ipp", &compar, 1, // our func
array, NARRAYELEMENTS, sizeof(int), // qsort args
-1); // compar args
if (res != 0){
return 2;
}
printarray();
return 0;
}