|
|
我在看一个c语言写的软件的源码,里面有几个文件是实现数据结构的..其中有list.h list.c这两个文件实现链表.别的地方都很好懂..就是有一处实在看不明白了.
list.h:
- #ifndef __list_h_
- # define __list_h_ 1
- struct list_element_s;
- typedef struct list_s {
- struct list_element_s *head;
- } list_t;
- /*
- * The function type for iterating over elements.
- */
- [color="Red"]typedef int (*list_iterator_t) (void *, void *);[/color]
- void list_init(struct list_s *list);
- void list_insert(struct list_s *list, const void *data, const char *key);
- const void *list_find(struct list_s *list, const char *key);
- void list_delete(struct list_s *list, const char *key);
- void list_foreach(struct list_s *list, list_iterator_t iter, void *data);
- void list_done(struct list_s *list);
- #endif /* __list_h */
复制代码
list.c:
- ........
- /*
- * Calls a given function for each element of the list.
- */
- void list_foreach(struct list_s *list, list_iterator_t iter, void *data) {
- struct list_element_s *element;
- for (element = list->head; element &&
- [color="Red"]iter((void *) element->data, data);[/color]
- element = element->next);
- }
- ........
复制代码
那个iterator本质上是什么东西呢? :ask |
|