好多人都是为了找实习、找工作,看看思路,手写下这个问题的代码。如果有机会还是最好真正调试一下,还是有很多细节需要注意的。不多说了,代码记录如下:
Node* Merge(Node *h1,Node *h2) { Node *head,*pCurrent,*head1,*head2; head1 = h1; head2 = h2; if(head1==NULL) return head2; else if(head2==NULL) return head1; head = head1->value < head2->value ? head1 : head2; if (head == head1) head1=head1->next; else head2=head2->next; pCurrent = head; while(head1!= NULL && head2!=NULL) { if(head1->value <= head2->value) { pCurrent->next = head1; pCurrent = pCurrent->next; head1 = head1->next; continue; } if(head1->value > head2->value) { pCurrent->next =head2; pCurrent = pCurrent->next; head2 = head2->next; continue; } } if(head1==NULL) { pCurrent->next = head2; } else if(head2 == NULL) { pCurrent->next = head1; } return head; };
原文地址:http://blog.csdn.net/dalongyes/article/details/26056641