比较简单,直接上代码。
package pers.mao.linkedList.demo_01;
/**
* @author Mao Qingbo
* @date 2021-02-01
*/
public class CommonPart {
public void printCommonPart(Node head1, Node head2){
System.out.println("Common Part: ");
while (head1 != null && head2 != null){
if(head1.value < head2.value){
head1 = head1.next;
}
else if(head2.value < head1.value){
head2 = head2.next;
}
else{
System.out.print(head1.value + " ");
head1 = head1.next;
head2 = head2.next;
}
}
System.out.println();
}
}
网友评论