Code:
/*
* Position iterator to head of list and return its data.
*/
void *lst_first(List *lst)
{
lst->iterator = lst->head;
if(lst->iterator != NULL)
return nd_getData(lst->iterator);
else
return NULL;
}
/*
* Position iterator to next node in list and return its data.
*/
void *lst_next(List *lst)
{
if(lst->iterator != NULL)
{
lst->iterator = nd_getNext(lst->iterator);
if(lst->iterator != NULL)
return nd_getData(lst->iterator);
}
return NULL;
}
and the list
Code:
/* Linked list data */
typedef struct
{
Node *head; /* First element in list */
Node *tail; /* last element in list */
Node *iterator; /* Used to iterate through list */
int size; /* number of elements currently in list */
} List;