-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.h
More file actions
47 lines (40 loc) · 1.52 KB
/
linkedlist.h
File metadata and controls
47 lines (40 loc) · 1.52 KB
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
/* =============================================================================
linkedlist.h
Linked list implementation that allows any data type to be stored.
Reference:
- Implementation of linked list structs inspired by Artem Polyvyanyy from
ass2-soln-2020.c.
Author: David Sha
============================================================================= */
#ifndef _LINKEDLIST_H_
#define _LINKEDLIST_H_
/* structures =============================================================== */
typedef struct node node_t;
struct node {
void *data;
node_t *next;
node_t *prev;
};
typedef struct list {
node_t *head;
node_t *foot;
} list_t;
/* function prototypes ====================================================== */
list_t *create_empty_list();
list_t *create_list(node_t *head, node_t *foot);
int is_empty_list(list_t *list);
void free_list(list_t *list, void (*free_data)(void *data));
list_t *prepend(list_t *list, void *data);
list_t *append(list_t *list, void *data);
int list_len(list_t *list);
void remove_node(list_t *list, node_t *node);
void *remove_data(list_t *list, void *data);
void *move_data(void *data, list_t *from, list_t *to);
void *pop(list_t *list);
void print_list(list_t *list, void (*print_data)(void *));
list_t *insert_prev(list_t *list, node_t *node, void *data);
list_t *insert_next(list_t *list, node_t *node, void *data);
void *find_node(list_t *list, void *data, int (*cmp)(void *, void *));
int cmp_addr(void *a, void *b);
void copy_list(list_t *from, list_t *to);
#endif