/*
*任务说明:链表合并
*姓名:陈冲
*学号:2015015234
*班级:2班
*日期:2016/6/30
*/
程序无法调试 一直没弄好
#include<stdio.h>
#include<malloc.h>
typedef struct node
{
int data;
struct node * next;
} Node;
void printList(Node * head);
Node * mergeList(Node * h1, Node * h2);
int main(void)
{
struct node a,b,c,d,x,y,z;
Node *head1,*head2;
head1=&a;
head2=&x;
a.data=15;
a.next=&b;
b.data=20;
b.next=&c;
c.data=35;
c.next=&d;
d.data=40;
d.next=NULL;
x.data=25;
x.next=&y;
y.data=30;
y.next=&z;
z.data=45;
z.next=NULL;
printList(mergeList(head1,head2));
return 0;
}
void printList(Node * head)
{
while(head!=NULL)
{
printf("%d\n",head->data);
head=head->next;
}
}
Node * mergeList(Node * h1, Node * h2)
{
Node *h3,*h4,*h5;
h4=h1;
h3=h1->next;
h5=h2;
for(;h5!=NULL;h5=h5->next)
{
for(;h1!=NULL;h1=h1->next)
{
h3=h1->next;
if((h2->data>40)&&(h3==NULL))
{
h1->next=h2;
h2->next=NULL;
}
if(h2->data>h1->data&&h2->data<h3->data )
{
h2->next=h1->next;
h1->next=h2;
}
}
}
return h4;
}