typedef struct node
{
int data;
struct node *next;
}Node;
Node *Merge(Node *head1, Node*head2)
{
Node *head=(Node *)malloc(sizeof(Node));
head->data=head1->data + head2->data;
head->next=NULL;
Node *p1=NULL;
Node *p2=NULL;
Node *p3=NULL;
p1=head1->next;
p2=head2->next;
head=p3=head1;
while(p1 && p2)
{
if(p1->data <= p2->data)
{
p3->next=p1;
p3=p1;
p1=p1->next;
}
else
{
p3->next=p2;
p3=p2;
p2=p2->next;
}
}
p3->next=p1 ? p1 : p2;
free(head2);
return head;
}
阅读(804) | 评论(0) | 转发(0) |