#include #include #include struct Node { int id; struct Node *next; }; typedef struct Node Node_t; Node_t *head = NULL; Node_t *tail = NULL; int main(void) { int i; for (i = 0; i < 10; i++) { if (head == NULL) { printf("head, adding id: %d\n", i); head = (Node_t *) malloc(sizeof(Node_t)); head->id = i; head->next = NULL; tail = head; } else { printf("tail, adding id: %d\n", i); Node_t *tmp = (Node_t *) malloc(sizeof(Node_t)); tmp->id = i; tmp->next = NULL; head->next = tmp; head = head->next; } } while (tail != NULL) { printf("tail: %d\n", tail->id); tail = tail->next; } return 0; }