public static void l1Unionl2(Hero head1
, Hero head2
) {
if (head1
.getNext() == null
|| head2
.getNext() == null
){
System
.out
.println("链表为空!!!");
return;
}
Hero temp1
= head1
.getNext();
Hero temp2
= head2
.getNext();
Hero k
= new Hero(0);
Hero temp
= k
;
while (temp1
!= null
&& temp2
!= null
){
if (temp1
.getNo() <= temp2
.getNo()){
temp
.setNext(temp1
);
temp
= temp1
;
temp1
= temp1
.getNext();
}else {
temp
.setNext(temp2
);
temp
= temp2
;
temp2
= temp2
.getNext();
}
}
if (temp1
!= null
){
temp
.setNext(temp2
);
}
if (temp2
!= null
){
temp
.setNext(temp1
);
}
while (k
.getNext() != null
){
System
.out
.println(k
.getNext());
k
= k
.getNext();
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-2489.html