>Does your linked list has a pointer to the last node?
Not built in, no. I decided against it for simplicity sake, though you can easily place an iterator to point at the end of the list if you need quick insertions there:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "List.h"
/* Error handling omitted in this example */
Iterator newItem(int data)
{
Iterator item = malloc(sizeof (*item));
item->data = malloc(sizeof (int));
*(int*)item->data = data;
item->prev = item->next = 0;
return item;
}
int main(void)
{
List head = 0;
Iterator tail;
int i;
for (i = 0; i < 10; i++)
head = ListAddBack(ListLast(head), newItem(i));
tail = ListLast(head);
head = ListFirst(head);
printf("First: %d\n", *(int*)ListContent(head));
printf("Last: %d\n", *(int*)ListContent(tail));
return 0;
}
It's a bit ugly with casting because of the void pointers. Try writing a generic library in C and you'll remember how much you love templates.