1 #include<stdio.h> 2 #include<stdlib.h> 3 4 typedef char Elemtype; 5 6 typedef struct node 7 { 8 Elemtype data; 9 struct node *next; 10 }Lnode,*Linklist; 11 12 void createHead(Linklist *L) 13 { 14 Linklist s; 15 int i; 16 printf("头插法: "); 17 *L = (Linklist)malloc(sizeof(Lnode)); 18 (*L)->next = NULL; 19 20 for(i=0;i<26;i++) 21 { 22 s = (Linklist)malloc(sizeof(Lnode)); 23 24 s->data = 65+i; 25 s->next = (*L)->next; 26 (*L)->next = s; 27 } 28 } 29 void createRear(Linklist *L) 30 { 31 Linklist s,rear; 32 int i; 33 printf("尾插法: "); 34 35 *L = (Linklist)malloc(sizeof(Lnode)); 36 rear = *L; 37 38 for(i=0;i<26;i++) 39 { 40 s = (Linklist)malloc(sizeof(Lnode)); 41 s->data = 65+i; 42 rear->next = s; 43 rear = s; 44 } 45 rear->next = NULL; 46 47 } 48 void print(Linklist L) 49 { 50 Linklist p = L->next; 51 while(p) 52 { 53 printf("%c ",p->data); 54 p = p->next; 55 } 56 printf(" "); 57 } 58 int main() 59 { 60 Linklist La,Lb; 61 62 createHead(&La); 63 print(La); 64 65 createRear(&Lb); 66 print(Lb); 67 68 return 0; 69 }