-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlinkedlist.h
43 lines (32 loc) · 1.24 KB
/
dlinkedlist.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
//
// dlinkedlist.h
// lwt
//
// Created by Tongliang Liu on 11/8/13.
// Copyright (c) 2013 cooniur. All rights reserved.
//
#ifndef lwt_dlinkedlist_h
#define lwt_dlinkedlist_h
typedef struct __dlst_t__ dlinkedlist_t;
typedef struct __dlst_el_t__ dlinkedlist_element_t;
struct __dlst_el_t__
{
void *data;
dlinkedlist_element_t *prev;
dlinkedlist_element_t *next;
};
dlinkedlist_t* dlinkedlist_init();
void dlinkedlist_free(dlinkedlist_t** list);
dlinkedlist_element_t* dlinkedlist_element_init(void* data);
void dlinkedlist_element_free(dlinkedlist_element_t** e);
dlinkedlist_element_t* dlinkedlist_first(dlinkedlist_t* list);
dlinkedlist_element_t* dlinkedlist_last(dlinkedlist_t* list);
size_t dlinkedlist_size(dlinkedlist_t* list);
int dlinkedlist_add(dlinkedlist_t* list, dlinkedlist_element_t* e);
dlinkedlist_element_t* dlinkedlist_find(dlinkedlist_t* list, void* data);
int dlinkedlist_remove(dlinkedlist_t* list, dlinkedlist_element_t* e);
#define dlinkedlist_foreach_element(e, list) \
size_t __dl_size = dlinkedlist_size(list); \
dlinkedlist_element_t *(e) = dlinkedlist_first(list); \
for (size_t __dl_i = 0; __dl_i < __dl_size; (e) = (e)->next, __dl_i++)
#endif // #ifndef lwt_dlinkedlist_h