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

两个递增的链表合并

  1. 使用递归,、
  2. 得出较小值后;剩下又是两个链表
  3. 重复动作用递归
 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                     }    

 

posted @ 2020-03-29 14:47  浪波激泥  阅读(251)  评论(0编辑  收藏  举报