-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
39 lines (30 loc) · 925 Bytes
/
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
#ifndef LIST_H
#define LIST_H
#include "decs.h"
typedef struct Node {
void *payload;
struct Node *next;
} Node;
// singly linked circular list
typedef struct {
Node *const sentinel; // const ptr to dummy node which marks the beginning and end of the list
Node *iter; // pointer to next node returned when iterating over the list
Node *prev; // allows for popping the current element during an iteration
int length;
} List;
// list creation/deletion
List* list_init();
void list_free(List *list, bool free_payloads);
// list modification
void list_add(List *list, void *payload);
void list_pop(List *list, bool free_payload);
// list iteration
void list_reset_iter(List *l);
bool list_has_next(List *l);
void* list_get_next(List *l);
// list query
int list_length(List *list);
// particle passing
void list_pass(List *recip, List *donor);
void list_combine(List *recip, List *donor);
#endif //LIST_H