user-0 提问: C语言：有序链表La 12345 Lb 2468 10按非减顺序放入链表Lc中，结果出来却是12234468 10 0 没有5，请各位大佬帮忙看看

回复:
user: user-0
content: 引用 4 楼 自信男孩的回复:#include<stdio.h> #include<stdlib.h>  /*define La*/ typedef struct node {     int data;     struct node *next; }NODE, *LIST;   LIST create_list(int *arr, int len) {     LIST phead = NULL, p, r;     int i;      for (i = 0; i < len; i++) {         p = (LIST)malloc(sizeof(NODE));         if (!p)             exit(0);         p->data = arr[i];         if (!phead) {             phead = p;             r = phead;         } else {             r->next = p;             r = p;         }     }     p->next = NULL;      return phead; }  void show_list(LIST phead) {     LIST p = phead;      while (p) {         printf("%d\t", p->data);         p = p->next;     }     putchar(10); }  LIST merge_list(LIST la, LIST lb) {     LIST lc = NULL;     LIST p, q, r;      p = la;     q = lb;     r = lc;      while (p && q) {         if (p->data < q->data) {             if (!lc) {                 lc = p;                 r = p;             } else {                 r->next = p;                 r = p;             }             p = p->next;         } else if (p->data > q->data) {             if (!lc) {                 lc = q;                 r =q;             } else {                 r->next = q;                 r = q;             }             q = q->next;         } else {             if (!lc) {                 lc = p;                 r = p;             } else {                 r->next = p;                 r = p;             }             p = p->next;         }     }      while (p) {         if (!lc) {             lc = p;             r = p;         } else {             r->next = p;             r = p;         }         p  = p->next;     }      while (q) {         if (!lc) {             lc = q;             r =q;         } else {             r->next = q;             r = q;         }         q = q->next;     }     r->next = NULL;      return lc; }  int main() {     int i;     LIST la, lb, lc;     int a[5] = { 1,2,3,4,5 };     int b[5] = { 2,4,6,8,10 };      /*build linked-list La*/     la = create_list(a, 5);      /*build linked-list Lb*/     lb = create_list(b, 5);      /*print linked-list La and Lb*/     show_list(la);     show_list(lb);      lc = merge_list(la, lb);     /*print Lc*/     show_list(lc);      return 0; }  供参考～ 谢谢大佬跪谢了。万分感谢

user: user-1
content: #include<stdio.h> #include<stdlib.h>  /*define La*/ typedef struct node {     int data;     struct node *next; }NODE, *LIST;   LIST create_list(int *arr, int len) {     LIST phead = NULL, p, r;     int i;      for (i = 0; i < len; i++) {         p = (LIST)malloc(sizeof(NODE));         if (!p)             exit(0);         p->data = arr[i];         if (!phead) {             phead = p;             r = phead;         } else {             r->next = p;             r = p;         }     }     p->next = NULL;      return phead; }  void show_list(LIST phead) {     LIST p = phead;      while (p) {         printf("%d\t", p->data);         p = p->next;     }     putchar(10); }  LIST merge_list(LIST la, LIST lb) {     LIST lc = NULL;     LIST p, q, r;      p = la;     q = lb;     r = lc;      while (p && q) {         if (p->data < q->data) {             if (!lc) {                 lc = p;                 r = p;             } else {                 r->next = p;                 r = p;             }             p = p->next;         } else if (p->data > q->data) {             if (!lc) {                 lc = q;                 r =q;             } else {                 r->next = q;                 r = q;             }             q = q->next;         } else {             if (!lc) {                 lc = p;                 r = p;             } else {                 r->next = p;                 r = p;             }             p = p->next;         }     }      while (p) {         if (!lc) {             lc = p;             r = p;         } else {             r->next = p;             r = p;         }         p  = p->next;     }      while (q) {         if (!lc) {             lc = q;             r =q;         } else {             r->next = q;             r = q;         }         q = q->next;     }     r->next = NULL;      return lc; }  int main() {     int i;     LIST la, lb, lc;     int a[5] = { 1,2,3,4,5 };     int b[5] = { 2,4,6,8,10 };      /*build linked-list La*/     la = create_list(a, 5);      /*build linked-list Lb*/     lb = create_list(b, 5);      /*print linked-list La and Lb*/     show_list(la);     show_list(lb);      lc = merge_list(la, lb);     /*print Lc*/     show_list(lc);      return 0; }  供参考～

user: user-0
content: 引用 2 楼 自信男孩的回复:只用一个函数来实现，不看着费劲吗？ 学C语言时老师没讲链表。这学期学数据结构要用链表。然后我懵了

user: user-1
content: 只用一个函数来实现，不看着费劲吗？

user: user-0
content: 救救孩子吧，求求各位大佬