代码实现
public static HeroNode unitePrint(HeroNode head1, HeroNode head2){
if(head1.next == null){
return head2.next;
}
if(head2.next == null){
return head1.next;
}
HeroNode newList = new HeroNode(0,"","");
HeroNode head = newList;//新链表的头结点
HeroNode cur1 = head1.next;
HeroNode cur2 = head2.next;
while(cur1 != null && cur2 != null){
if(cur1.no < cur2.no){
newList.next = cur1;
cur1 = cur1.next;
}else{
newList.next = cur2;
cur2 = cur2.next;
}
newList = newList.next;
}
if(cur1 == null){
while(cur2 != null){
newList.next = cur2;
cur2 = cur2.next;
newList = newList.next;
}
}else{
while(cur1 != null){
newList.next = cur1;
cur1 = cur1.next;
newList = newList.next;
}
}
return head;
}