/** * c语言实现正序链表的创建(不使用头结点); */ #include <stdio.h> #include <malloc.h> typedef struct node { int data; struct node *next; }ArrayNode, *ArrayPoint; void swop(int a[], int aLength) { ArrayPoint head, p, q; for(int i=0; i<aLength; i++) { if(i==0) { p = (ArrayPoint)malloc(sizeof(ArrayNode)); head = p; p->data = a[i]; } else { p->next = (ArrayPoint)malloc(sizeof(ArrayNode)); p = p->next; p->data = a[i]; } } /*链表的打印*/ printf("链表数组为: /n"); for(int i=0; i<aLength; i++) { printf("%d/n",head->data); head = head->next; } } main() { void swop(int a[], int aLength); int a[] = {2,3,5,6,7,8,11,13,15,19}; int b[] = {1,2,4,5,7,9,10,12,14,20}; swop(a, 10); swop(b, 10); }