1 struct node{ 2 int i; 3 struct node* next; 4 };typedef struct node list; 5 typedef struct node* pointer; 6 printfpointer(pointer A){ 7 while(A!=NULL){ 8 printf("%d\n",A->i); 9 A=A->next; 10 } 11 }//打印链表A 12 13 void a(pointer a,pointer b) 14 { 15 pointer c=NULL,head; 16 while(a!=NULL) 17 { 18 while(a!=NULL&&b!=NULL&&a->i>b->i) 19 { 20 if(head==NULL) 21 { 22 head=(pointer)malloc(sizeof(list)); 23 c=head; 24 c->next=NULL; 25 26 }//头指针的存储 27 c->next =(pointer)malloc(sizeof(list)); 28 c=c->next; 29 c->i=b->i; 30 c->next=NULL; 31 a=a->next; 32 b=b->next; 33 } 34 if(a!=NULL&&b!=NULL&&a->i==b->i) 35 { 36 b=b->next; 37 }//a->i==b->i情况 38 if(c!=NULL){ 39 40 c->next =(pointer)malloc(sizeof(list)); 41 c=c->next; 42 c->i=a->i; 43 c->next=NULL; 44 a=a->next; 45 }//头指针没经过while循环,需要在这里处理 46 else { 47 head=(pointer)malloc(sizeof(list)); 48 head->i=a->i; 49 c=head; 50 c->next=NULL; 51 a=a->next; 52 } 53 } 54 while(b!=NULL) 55 { 56 c->next=(pointer)malloc(sizeof(list)); 57 c=c->next; 58 c->i=b->i; 59 b=b->next; 60 c->next=NULL; 61 62 }//a扫描完还有b剩下的情况 63 printfpointer(head); 64 }
a,b两个链表是升序排列的