-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
47 lines (34 loc) · 1.18 KB
/
list.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
37
38
39
40
41
42
43
44
45
46
47
// Unidirectional linked list
typedef struct Node {
struct Node *next;
int val;
} Node;
typedef struct List {
struct Node *start;
} List;
void list_init(List *list);
void list_free(List *list);
// Creates a list with the 'len' int values from the variable argument list, in
// the same order
void list_make(List *list, size_t len, ...);
// Adds 'val' to the beginning of 'list'
void list_add(List *list, int val);
// Returns true if 'list' has length 'len' and contains the 'len' int values
// from the variable argument list, in the same order
bool list_equals(List *list, size_t len, ...);
// Returns true if lists 'l1' and 'l2' are equal
bool lists_equal(List *l1, List *l2);
// Returns true if the values in 'list' are monotonically increasing
bool list_is_sorted(List* list);
// Removes the first instance of 'val' from 'list'
void list_remove(List *list, int val);
// Removes all instances of 'val' from 'list'
void list_remove_all(List *list, int val);
// Reverses 'list'
void list_reverse(List *list);
// Sort functions
void list_selection_sort(List *list);
void list_insertion_sort(List *list);
void list_mergesort(List *list);
// Prints 'list'
void list_print(List *list);