list.h
1.38 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
/* Double-linked list routines */
#ifndef __LIST
#define __LIST
typedef struct sElement {
void *pContent;
struct sElement *pNext;
struct sElement *pPrev;
} tElement;
typedef tElement *tPosition;
typedef struct sList {
int nCount;
struct sElement Header;
} tList;
typedef int tVisitFunc(); /* return 1 to abort */
/* tVisitFunc(void *pContent, void *pArgs); */
void List_Init(tList *pList);
int List_IsEmpty(tList *pList);
int List_GetCount(tList *pList);
tPosition List_AddAfter(tList *pList, tPosition pos, void *pContent);
tPosition List_AddBefore(tList *pList, tPosition pos, void *pContent);
tPosition List_AddHead(tList *pList, void *pContent);
tPosition List_AddTail(tList *pList, void *pContent);
tPosition List_GotoHead(tList *pList);
tPosition List_GotoTail(tList *pList);
void *List_GetNext(tList *pList, tPosition *ppos);
void *List_GetPrev(tList *pList, tPosition *ppos);
void *List_RemoveAt(tList *pList, tPosition pos);
void *List_RemoveHead(tList *pList);
void *List_RemoveTail(tList *pList);
tPosition List_Find(tList *pList, void *pContent);
void *List_GetAt(tList *pList, tPosition pos);
tPosition List_TraverseForward(tList *pList, tPosition pos, tVisitFunc *pVisitFunc, void *pArgs);
tPosition List_TraverseBackward(tList *pList, tPosition pos, tVisitFunc *pVisitFunc, void *pArgs);
void List_Sort(tList *pList, int (*comp)(const void *pContent1, const void *pContent2));
#endif