forked from troydhanson/uthash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest46.c
84 lines (81 loc) · 2.13 KB
/
test46.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
#include <stdio.h>
#include "utarray.h"
static int strsort(const void *_a, const void *_b)
{
const char *a = *(const char* const *)_a;
const char *b = *(const char* const *)_b;
return strcmp(a,b);
}
static int revsort(const void *_a, const void *_b)
{
const char *a = *(const char* const *)_a;
const char *b = *(const char* const *)_b;
return strcmp(b,a);
}
int main()
{
UT_array *strs,*strs2;
char *s, **p=NULL;
utarray_new(strs, &ut_str_icd);
s=(char*)"hello";
utarray_push_back(strs, &s);
s=(char*)"world";
utarray_push_back(strs, &s);
while ( (p=(char**)utarray_next(strs,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
s=(char*)"begin";
utarray_insert(strs,&s,0);
while ( (p=(char**)utarray_next(strs,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
utarray_new(strs2, &ut_str_icd);
s=(char*)"alt";
utarray_push_back(strs2, &s);
s=(char*)"oth";
utarray_push_back(strs2, &s);
utarray_inserta(strs2, strs, 1);
while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
utarray_erase(strs2,0,2);
while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
utarray_pop_back(strs2);
while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
utarray_concat(strs2, strs);
while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
utarray_clear(strs2);
utarray_concat(strs2, strs);
while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
printf("sorting strs2\n");
utarray_sort(strs2,strsort);
while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
printf("reverse sorting strs2\n");
utarray_sort(strs2,revsort);
while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
printf("%s ",*p);
}
printf("\n");
utarray_clear(strs2);
utarray_free(strs2);
utarray_free(strs);
return 0;
}