-
Notifications
You must be signed in to change notification settings - Fork 11
/
ArrayList.h
37 lines (25 loc) · 881 Bytes
/
ArrayList.h
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
#ifndef __ARRAYLIST_H__
#define __ARRAYLIST_H__
#ifndef ARRAYLIST_INIT_CAPACITY
#define ARRAYLIST_INIT_CAPACITY 16
#endif
typedef int (*ArrayListCompareFunc)(void *a, void *b);
struct ArrayList {
void **data;
int length; /* number of elements */
int capacity; /* capacity of arraylist */
};
typedef struct ArrayList *ArrayList;
ArrayList arrlist_new();
int arrlist_destroy(ArrayList a);
int arrlist_size(ArrayList a);
int arrlist_append(ArrayList a, void *val);
int arrlist_remove(ArrayList a, int index);
int arrlist_insert(ArrayList a, int index, void *val);
void *arrlist_get(ArrayList a, int index);
int arrlist_set(ArrayList a, int index, void *val);
/* In-place reverse */
void arrlist_reverse(ArrayList a);
/* sortOrder(0): Ascending, otherwise: Descending */
void arrlist_sort(ArrayList a, ArrayListCompareFunc compareFn, int sortOrder);
#endif