#include <stdio.h> typedef struct ListNode* Ptrnode; struct ListNode{ int data; Ptrnode NEXT; }; Ptrnode BuildList(int n, int a[]); void ShowList(Ptrnode P, int n); int main(void) { int n, i; Ptrnode P; scanf("%d\n",&n); int a[n]; for(i = 0; i < n; i++) { scanf("%d",&a[i]); } P = BuildList(n, a); ShowList(P, n); return 0; } Ptrnode BuildList(int n, int a[]) { Ptrnode Pp = (Ptrnode) malloc(sizeof(struct ListNode)); Pp->data = 0; Pp->NEXT = NULL; Ptrnode tmp = Pp; for(int i = 0; i < n; i++) { Ptrnode Pm = (Ptrnode) malloc(sizeof(struct ListNode)); Pm ->data = a[i]; Pm ->NEXT = NULL; Pp ->NEXT = Pm; Pp = Pm; } return tmp->NEXT; } void ShowList(Ptrnode P, int n) { for(int i = 0; i < n; i++) { printf("%d ",P->data); P = P->NEXT; } }