public static Node mergeTwoLists(Node headA,Node headB){
Node newHead=new Node(-1);
Node tmp=newHead;
while(headA!=null&&headB!=null){
if(headA.data<headB.data){
tmp.next=headA;
tmp=tmp.next;
headA=headA.next;
}else{
tmp.next=headB;
tmp=tmp.next;
headB=headB.next;
}
}
if(headA==null){
tmp.next=headA;
}
if(headA==null){
tmp.next=headB;
}
return newHead.next;
}
把两个有序单链表,合并为一个单链表
最新推荐文章于 2023-04-13 19:47:20 发布