#include <stdio.h> #include <stdlib.h> typedef struct ListNode { int val; struct ListNode* next; } ListNode; struct ListNode* createNode(int v) { struct ListNode* node = malloc(sizeof(struct ListNode)); node->val = v; node->next = NULL; return node; } int main() { int n; while (scanf("%d", &n) != EOF) { int v; scanf("%d", &v); struct ListNode* head = createNode(v); struct ListNode* tmp = head; for(int i = 0; i < n - 1; i++) { scanf("%d", &v); struct ListNode* node = createNode(v); tmp->next = node; tmp = tmp->next; } tmp = head; while(tmp != NULL) { printf("%d ", tmp->val); tmp = tmp->next; } while(head) { tmp = head; head = head->next; free(tmp); } free(head); } return 0; }