/
list.h
41 lines (34 loc) · 1.26 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
38
39
40
41
#ifndef LIST_H_
#define LIST_H_
#if defined(__cplusplus)
extern "C" {
#endif
typedef void* ListElement;
typedef struct listnode{
ListElement element;
struct listnode * nextNode;
}*ListNode;
typedef struct list *List;
//无序列表
struct list{
ListNode dataNodes;
void (*addFirst)(List this,ListElement); //添加元素到列表头.
void (*addLast)(List this,ListElement); //添加元素到列表尾部.
void (*removeFirst)(List this); //删除列表头部元素.
void (*removeLast)(List this); //删除链表尾部元素.
ListNode (*first)(List this); //获取列表第一个节点.
ListNode (*last)(List this); //获取列表最后一节点.
int (*size)(List this);
void (*clearNode)(List this, ListNode); //节点释放函数
void (*clearElement)(ListElement); //节点资源释放函数
void (*forEach)(List this, void(*)(ListNode, void*), void*); //遍历节点
ListNode (*get)(List this, int index); // 得到指定位置的节点
void (*deleteIndex)(List this, int index); // 得到指定位置的节点
void (*clearAll) (List this); // 清除所有
};
List newList(void (*clearElement)(ListElement)); //new一个列表对象
void delList(List this); //删除一个列表对象
#if defined(__cplusplus)
}
#endif
#endif /* LIST_H_ */