forked from cartoon-raccoon/gdscutm-c-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliblinkedlist.h
46 lines (34 loc) · 1.28 KB
/
liblinkedlist.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
// declaring a node struct
typedef struct node {
int value;
struct node *next;
} node;
// declaring the wrapper struct
typedef struct linkedlist {
int len;
struct node *head;
} linkedlist;
// ====== FUNCTION PROTOTYPES ====== //
// constructor and destructor functions
/// Allocates a new linked list.
/// Returns a null pointer if the underlying allocation fails.
linkedlist *linkedlist_create(void);
/// Deallocates all the nodes in `list` and then deallocates `list` itself.
void linkedlist_destroy(linkedlist *list);
// linked list methods
/// Pushes a new item to the head of the linked list,
/// moving all items down by one index.
int linkedlist_push(linkedlist *list, int item);
/// Appends a new item to the end of the linked list.
/// Item indexes do not change.
int linkedlist_append(linkedlist *list, int item);
/// Removes the first element in the list,
/// moving all items up by one index.
int linkedlist_pop(linkedlist *list);
/// Removes an item from the list at the specified index,
/// deallocating the node and returning its value.
int linkedlist_remove(linkedlist *list, int idx);
/// Returns the value of the node at the specified index.
int *linkedlist_index(linkedlist *list, int idx);
/// Prints all the list's items.
void linkedlist_print(linkedlist *list);