user-0 提问: c语言链表问题，求大神解答！！！

回复:
user: user-1
content: 这个头像似曾相识

user: user-2
content: 数据结构对单链表进行数据排序 http://bbs.csdn.net/topics/392201633

user: user-3
content: #include <stdio.h> #include <stdlib.h>  typedef struct T_Node{     int d;     struct T_Node *next; } Node, *List;  void createlink(List *pla, List *plb) {     int i;     Node *p, *q;      *pla = (Node *)malloc(sizeof(Node));     //创建头结点     q = *pla;      for(i = 1; i <=10;i++)     {         p = (Node *)malloc(sizeof(Node));         p->d = i*2;         q->next = p;         q = p;     }     p->next = NULL;       *plb = (Node *)malloc(sizeof(Node));     //创建头结点     q = *plb;      for(i = 1; i <= 8;i++)     {         p = (Node *)malloc(sizeof(Node));         p->d = i+6;         q->next = p;         q = p;     }     p->next = NULL; }  //int  Intersection (List La, List Lb) void  Intersection (List La, List Lb) { #if 0     Node *p, *q, *r;     int i, j;     p = La->next;     q = Lb->next;     r = La;     for (i = 0; i < 8; i++) {         for (j = 0; j < 8; j++) {             if (p->d != q->d) {                 Node *t;                 t = p;                 r->next = t->next;                 free(t);             }             q = q->next;         }         p = p->next;         r = r->next;     }     return 0; #endif      Node *p, *q, *r, *s;      p = La->next;     q = Lb->next;     r = La;     while (p && q) {         if (p->d == q->d) {             p = p->next;             q = q->next;             r = r->next;         } else if (p->d > q->d){             q = q->next;         } else {             r->next = p->next;             s = p;             p = p->next;             free(s);         }     }     r->next = NULL;     while (p) {         s = p;         //printf("%d\n", p->d);         p = p->next;         free(s);     } //}; }  void show_list(List phead) {     if (!phead)         return;      List p = phead->next;      while (p) {         printf("%d\t", p->d);         p = p->next;     }     putchar(10); }  //void main() int main() {     //int i;     List la, lb;     //Node *p;     createlink(&la, &lb);     printf("Show list a: \n");     show_list(la);     printf("Show list b: \n");     show_list(lb);     Intersection (la, lb);     printf("Show list a: \n");     show_list(la);     /*     p = la->next;     while(p!=NULL)     {         printf("%4d",p->d);         p = p->next;     }     */     printf("\n"); }  供参考～

user: user-0
content: 引用 5 楼 自信男孩 的回复:#include <stdio.h> #include <stdlib.h>  typedef struct T_Node{     int d;     struct T_Node *next; } Node, *List;  void createlink(List *pla, List *plb) {     int i;     Node *p, *q;      *pla = (Node *)malloc(sizeof(Node));     //创建头结点     q = *pla;      for(i = 1; i <=10;i++)     {         p = (Node *)malloc(sizeof(Node));         p->d = i*2;         q->next = p;         q = p;     }     p->next = NULL;       *plb = (Node *)malloc(sizeof(Node));     //创建头结点     q = *plb;      for(i = 1; i <= 8;i++)     {         p = (Node *)malloc(sizeof(Node));         p->d = i+6;         q->next = p;         q = p;     }     p->next = NULL; }  //int  Intersection (List La, List Lb) void  Intersection (List La, List Lb) { #if 0     Node *p, *q, *r;     int i, j;     p = La->next;     q = Lb->next;     r = La;     for (i = 0; i < 8; i++) {         for (j = 0; j < 8; j++) {             if (p->d != q->d) {                 Node *t;                 t = p;                 r->next = t->next;                 free(t);             }             q = q->next;         }         p = p->next;         r = r->next;     }     return 0; #endif      Node *p, *q, *r, *s;      p = La->next;     q = Lb->next;     r = La;     while (p && q) {         if (p->d == q->d) {             p = p->next;             q = q->next;             r = r->next;         } else if (p->d > q->d){             q = q->next;         } else {             r->next = p->next;             s = p;             p = p->next;             free(s);         }     }     r->next = NULL;     while (p) {         s = p;         //printf("%d\n", p->d);         p = p->next;         free(s);     } //}; }  void show_list(List phead) {     if (!phead)         return;      List p = phead->next;      while (p) {         printf("%d\t", p->d);         p = p->next;     }     putchar(10); }  //void main() int main() {     //int i;     List la, lb;     //Node *p;     createlink(&la, &lb);     printf("Show list a: \n");     show_list(la);     printf("Show list b: \n");     show_list(lb);     Intersection (la, lb);     printf("Show list a: \n");     show_list(la);     /*     p = la->next;     while(p!=NULL)     {         printf("%4d",p->d);         p = p->next;     }     */     printf("\n"); }  供参考～ 引用 5 楼 自信男孩 的回复:#include <stdio.h> #include <stdlib.h>  typedef struct T_Node{     int d;     struct T_Node *next; } Node, *List;  void createlink(List *pla, List *plb) {     int i;     Node *p, *q;      *pla = (Node *)malloc(sizeof(Node));     //创建头结点     q = *pla;      for(i = 1; i <=10;i++)     {         p = (Node *)malloc(sizeof(Node));         p->d = i*2;         q->next = p;         q = p;     }     p->next = NULL;       *plb = (Node *)malloc(sizeof(Node));     //创建头结点     q = *plb;      for(i = 1; i <= 8;i++)     {         p = (Node *)malloc(sizeof(Node));         p->d = i+6;         q->next = p;         q = p;     }     p->next = NULL; }  //int  Intersection (List La, List Lb) void  Intersection (List La, List Lb) { #if 0     Node *p, *q, *r;     int i, j;     p = La->next;     q = Lb->next;     r = La;     for (i = 0; i < 8; i++) {         for (j = 0; j < 8; j++) {             if (p->d != q->d) {                 Node *t;                 t = p;                 r->next = t->next;                 free(t);             }             q = q->next;         }         p = p->next;         r = r->next;     }     return 0; #endif      Node *p, *q, *r, *s;      p = La->next;     q = Lb->next;     r = La;     while (p && q) {         if (p->d == q->d) {             p = p->next;             q = q->next;             r = r->next;         } else if (p->d > q->d){             q = q->next;         } else {             r->next = p->next;             s = p;             p = p->next;             free(s);         }     }     r->next = NULL;     while (p) {         s = p;         //printf("%d\n", p->d);         p = p->next;         free(s);     } //}; }  void show_list(List phead) {     if (!phead)         return;      List p = phead->next;      while (p) {         printf("%d\t", p->d);         p = p->next;     }     putchar(10); }  //void main() int main() {     //int i;     List la, lb;     //Node *p;     createlink(&la, &lb);     printf("Show list a: \n");     show_list(la);     printf("Show list b: \n");     show_list(lb);     Intersection (la, lb);     printf("Show list a: \n");     show_list(la);     /*     p = la->next;     while(p!=NULL)     {         printf("%4d",p->d);         p = p->next;     }     */     printf("\n"); }  供参考～ 谢谢大神，看了你的代码我找到错误的原因了！！！感谢！！

user: user-4
content: 我一般没这么用，，，找半天原因。  把createlink里面的pla和plb前面的*全部去掉

user: user-0
content: 引用 2 楼 user-4 的回复:感觉创建链表有点问题。整体贴一下代码吧。 这是全部的代码，求大神解答！！ #include <stdio.h> #include <stdlib.h>  typedef struct T_Node{     int d;     struct T_Node *next; } Node, *List;  void createlink(List *pla, List *plb) {     int i;     Node *p;      *pla = (Node *)malloc(sizeof(Node));     //创建头结点     p = *pla;      for(i = 1; i <=10;i++)     {         p->next = (Node *)malloc(sizeof(Node));         p = p->next;         p->d = i*2;         p->next = NULL;     }       *plb = (Node *)malloc(sizeof(Node));     //创建头结点     p = *plb;      for(i = 1; i <= 8;i++)     {         p->next = (Node *)malloc(sizeof(Node));         p = p->next;         p->d = i+6;         p->next = NULL;     } }  int  Intersection (List La, List Lb){     Node *p, *q, *r;     int i, j;     p = La->next;     q = Lb->next;     r = La;     for (i = 0; i < 8; i++) {         for (j = 0; j < 8; j++) {             if (p->d != q->d) {                 Node *t;                 t = p;                 r->next = t->next;                 free(t);             }             q = q->next;         }         p = p->next;         r = r->next;     }     return 0; };  void main() {     int i;     List la, lb;     Node *p;     createlink(&la, &lb);     Intersection (la, lb);     p = la->next;     while(p!=NULL)     {         printf("%4d",p->d);         p = p->next;     }     printf("\n"); }

user: user-4
content: 感觉创建链表有点问题。整体贴一下代码吧。

user: user-4
content: main函数自己写的吗？不是的话格式化一下再贴上来。