Updated project to use eclipse build tools and make system.
[C-Data-Structures.git] / lib_ll.h
blobb154791638a193b69eeda7aa27dbff554ef71f3c
1 #ifndef LIB_LL_H_
2 #define LIB_LL_H_
4 typedef struct list_node {
5 void *pData;
6 struct list_node *pNext;
7 } List_Node;
9 typedef struct {
10 struct list_node *pNext;
11 int count;
12 } List_Head;
14 /* return address of next node in list */
15 #define list_next(element) ((element)->pNext)
17 /* return address of data in this node */
18 #define list_data(element) ((element)->pData)
20 /* test node to determine if it is the head of list */
21 #define list_is_head(list, element) ((element) == (list)->pNext ? 1 : 0)
23 /* test node to determine if it is the tail of list */
24 #define list_is_tail(element) ((element)->pNext == NULL ? 1 : 0)
26 /* remove next node in list */
27 #define list_rm_next(list, element) list_rm_node(list, (element)->pNext)
29 /* return pointer to the head node in the list */
30 #define list_head(list) ((list)->pNext)
32 /* return integer value of the size of the list */
33 #define list_size(list) ((list)->count)
35 /* create new empty list */
36 List_Head *list_new(void);
38 /* completely delete list and return all memory to heap */
39 void list_delete(List_Head *);
41 /* returns length of list.
42 returns integer count of number of nodes in list.
43 if pointer passed to function is null, returns -1 value.
45 int list_len(List_Head *);
47 /* search through list for pointer to node*/
48 int list_search(List_Head *pHead, List_Node *pNode);
50 /* return address of end of list */
51 List_Node *list_tail(List_Head *);
53 /* push new node on head of list */
54 List_Node *list_ins_head(List_Head *);
56 /* push new node on head of list - with data */
57 List_Node *list_ins_head_data(List_Head *pHead, void *Data);
59 /* push new node on tail of list */
60 List_Node *list_ins_tail(List_Head *);
62 /* push new node on tail of list - with data */
63 List_Node *list_ins_tail_data(List_Head *pHead, void *Data);
65 /* insert node before this node in list */
66 List_Node *list_ins_before(List_Head *, List_Node *);
68 /* insert node after this node in list */
69 List_Node *list_ins_after(List_Head *, List_Node *);
71 /* node remove (by address) */
72 int list_rm_node(List_Head *pHead, List_Node *);
74 /* remove node before this address if it exists
75 returns 1 if ok, -1 list empty or did not contain specified node
77 int list_rm_before(List_Head *pHead, List_Node *);
79 /* make a deep copy of list */
80 int list_copy(List_Head *pDest, List_Head *pSrc);
82 /* print out contents of list to stdout */
83 void list_print(List_Head *pHead);
85 /* get address of node at num - first node is 1 */
86 List_Node *list_get_num(List_Head *pHead, int count);
88 /* reverse current nodes - modify pointer to next in each */
89 int list_node_swap(List_Node *pPrev, List_Node *pCurr);
91 /* reverse contents of list */
92 List_Head *list_reverse(List_Head *pHead);
94 /* append high list to last node of low list - does not modify pHi list */
95 void list_append(List_Head *pLo, List_Head *pHi);
97 /* return an array of pointers to data payload in list - does not modify list */
98 int list_data_array(List_Head *pHead, void *pArr[], int len);
100 /* return an array of pointers to nodes in list - does not modify list */
101 int list_node_array(List_Head *pHead, void *pArr[], int len);
103 /* remove all nodes in list and free memory for each node */
104 void list_clear(List_Head *);
106 /* return address of previous node in list
107 returns NULL if no node found -- address of node otherwise
109 List_Node *list_prev_node(List_Head *pHead, List_Node *pNode);
111 #endif /* LIB_LL_H_ */