user-0 提问: 关于链表的题 

回复:
user: user-1
content: 对比一下找不同的地方，分析一下；

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

user: user-0
content: 引用 1楼自信男孩 的回复:#include<stdio.h> #include<stdlib.h>  struct node {     int data;     struct node *next; };  int main() {     int n,m,x,y,i,j;     scanf("%d %d",&m,&n);     struct node *head1,*head2,*q,*p,*t,*q1,*q2,*k;     head1=(struct node*)malloc(sizeof(struct node));     head1->next=NULL;     head2=(struct node*)malloc(sizeof(struct node));     head2->next=NULL;     q1 = head1;     q2 = head2;     for(i=1; i<=m; i++)     {         p = (struct node*)malloc(sizeof(struct node));         scanf("%d",&p->data);         p->next = NULL;         q1->next = p;         q1 = p;     }     for(i = 1; i<=n; i++)     {         p=(struct node*)malloc(sizeof(struct node));;         scanf("%d",&p->data);         p->next=NULL;         q2->next = p;         q2 = p;     }     q1 = head1->next;     q2 = head2->next;     t = head1;      while (q1 && q2) {         if (q1->data < q2->data) {             t->next = q1;             t = q1;             q1 = q1->next;         } else {             t->next = q2;             t = q2;             q2 = q2->next;         }     }     t->next = q1 ? q1 : q2;      p = head1->next;     while(p)     {         printf("%d ",p->data);         p = p->next;     }     /*     p = head2->next;     while(p)     {         k=p;         t=head1->next;         q=head1;         while(t)         {             if(k->data<t->data)             {                 k->next=t;                 q->next=k;                 break;             }             t=t->next;             q=q->next;         }         if(t==NULL)         {             k->next=NULL;             q->next=k;         }         p=p->next;     }     p=head1->next;     while(p)     {         if(p->next==NULL)             printf("%d\n",p->data);         else             printf("%d ",p->data);         p=p->next;     }     */     return 0; }   参考一下吧  合并和输出可以对比参考一下；我的那为啥不对

user: user-1
content: #include<stdio.h> #include<stdlib.h>  struct node {     int data;     struct node *next; };  int main() {     int n,m,x,y,i,j;     scanf("%d %d",&m,&n);     struct node *head1,*head2,*q,*p,*t,*q1,*q2,*k;     head1=(struct node*)malloc(sizeof(struct node));     head1->next=NULL;     head2=(struct node*)malloc(sizeof(struct node));     head2->next=NULL;     q1 = head1;     q2 = head2;     for(i=1; i<=m; i++)     {         p = (struct node*)malloc(sizeof(struct node));         scanf("%d",&p->data);         p->next = NULL;         q1->next = p;         q1 = p;     }     for(i = 1; i<=n; i++)     {         p=(struct node*)malloc(sizeof(struct node));;         scanf("%d",&p->data);         p->next=NULL;         q2->next = p;         q2 = p;     }     q1 = head1->next;     q2 = head2->next;     t = head1;      while (q1 && q2) {         if (q1->data < q2->data) {             t->next = q1;             t = q1;             q1 = q1->next;         } else {             t->next = q2;             t = q2;             q2 = q2->next;         }     }     t->next = q1 ? q1 : q2;      p = head1->next;     while(p)     {         printf("%d ",p->data);         p = p->next;     }     /*     p = head2->next;     while(p)     {         k=p;         t=head1->next;         q=head1;         while(t)         {             if(k->data<t->data)             {                 k->next=t;                 q->next=k;                 break;             }             t=t->next;             q=q->next;         }         if(t==NULL)         {             k->next=NULL;             q->next=k;         }         p=p->next;     }     p=head1->next;     while(p)     {         if(p->next==NULL)             printf("%d\n",p->data);         else             printf("%d ",p->data);         p=p->next;     }     */     return 0; }   参考一下吧  合并和输出可以对比参考一下；