类似于归并排序最后的merge过程
A>B那么B继续向前走 A<B那么A继续向前走 A=B那么打印并且都向前走
public class Node{
public int value;
public Node next;
public Node(int data) {
this.value = data;
}
}
public void printCommonPart(Node one, Node two) {
System.out.println("Common Part: ");
while (one != null && two != null) {
if (one.value < two.value) {
one = one.next;
} else if (one.value > two.value) {
two = two.next;
} else {
System.out.print(one.value);
one = one.next;
two = two.next;
}
}
System.out.println(" ");
}