面试题二十五:合并两个排序的链表

两个递增的链表合并

 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                     }    

猜你喜欢

转载自www.cnblogs.com/niliuxiaocheng/p/12592266.html