-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist.h
38 lines (32 loc) · 1.12 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
/*************************************************************************
> File Name: list.h
> Author: ellochen
> Mail: [email protected]
> Created Time: Wed May 15 22:45:11 2013
************************************************************************/
//the implement refers to <<Mastering Algorithms with C>>
#ifndef _LIST_H_
#define _LIST_H_
typedef struct _ListElmt{
void *data;
struct _ListElmt *next;
}ListElmt;
typedef struct _List{
int size;
int (*match)(const void *key1, const void *key2);
void (*destroy)(void *data);
ListElmt *head;
ListElmt *tail;
}List;
void listInit(List *list, void (*destory)(void *data));
void listDestory(List *list);
int listInsertNext(List *list, ListElmt *element, const void *data);
int listRemoveNext(List *list, ListElmt *element, void **data);
#define listSize(list) ((list)->size)
#define listHead(list) ((list)->head)
#define listTail(list) ((list)->tail)
#define listIsHead(list, element) ((element) == (list)->head ? 1 : 0)
#define listIsTail(element) ((element)->next == NULL ? 1 : 0)
#define listData(element) ((element)->data)
#define listNext(element) ((element)->next)
#endif