#include #include #include struct list { char *str; struct list *prev; struct list *next; }; int main (void) { unsigned int i; struct list *start, *end, *current, *tmp; start = NULL; for (i = 0; i < 10; i++) { struct list *entry; entry = malloc (sizeof (struct list)); entry->str = malloc (strlen ("hello-N") + 1); sprintf (entry->str, "hello-%d", i); if (!start) { start = current = entry; start->prev = NULL; } else { tmp = current; current->next = entry; current = current->next; current->prev = tmp; } } current->next = NULL; end = current; for (current = start; current; current = current->next) puts (current->str); for (current = end; current; current = current->prev) puts (current->str); for (current = start; current; current = tmp) { tmp = current->next; free (current->str); free (current); } exit (EXIT_SUCCESS); }