题目:打印两个有序链表的公共部分
package com.chenyu.zuo.linkedList;
/*** 打印有序链表的公共部分* @author 陈喻*题目:给定两个有序链表的头指针head1和head2,打印出两个链表的公共部分*思路:因为有序*如果head1的值小于head2,则head1往下移动*如果head2的值小于head1,则head2往下移动*如果head1的值和head2的值相等,则打印这个值,然后head1和head2都往下移动*head1或者head2有任何一个移动到null,整个过程停止*/
public class PrintCommonPart {public static class Node{//内部类public Node next;public int value;public Node(int value){this.value=value;} public Node(){}}/*** 打印链表公共部分的方法* @param head1* @param head2*/public void printCommonPart(Node head1,Node head2){if(head1==null || head2==null){return ;}while(head1!=null&&head2!=null){if(head1.value<head2.value){head1=head1.next;}else if(head1.value>head2.value){head2=head2.next;}else{