#include #include struct node { int data; struct node *next; }; struct list { struct node *head; }; void listAppend(struct list *list, int value) { if (list == NULL) { return; } list->head = doListAppend(list->head, value); } struct node *doListAppend(struct node *node, int value) { if (node == NULL) { return newNode(value); } node->next = doListAppend(node->next, value); return node; } struct node *newNode(int value) { struct node *n = malloc(sizeof(struct node)); n->data = value; n->next = NULL; return n; } void printList(struct list *list) { struct node *current = list->head; while (current != NULL) { printf("%d ", current->data); current = current->next; } printf("\n"); } int main(void) { struct list *myList = malloc(sizeof(struct list)); myList->head = NULL; listAppend(myList, 10); listAppend(myList, 20); listAppend(myList, 30); listAppend(myList, 40); printf("List contents: "); printList(myList); return 0; }