面试题二十五:合并两个排序的链表
两个递增的链表合并
- 使用递归,、
- 得出较小值后;剩下又是两个链表
- 重复动作用递归
1 ListNode f12( LstNode head1,LstNode head2){ 2 if(head1==null ) return head2; 3 if( head1== null ) return head1; 4 5 LstNode newhead =null; 6 7 if( head1.value<head2.value) 8 { 9 newhead =head2; 10 newhead.next = f12 ( head2.next ,head1 ); 11 } 12 else { 13 newhead =head1 14 newhead.next = f12 ( head1.next ,head2 ); 15 } 16 17 return newhead; 18 }
浪波激泥