順序付きチェーンテーブルの結合


public static Node mergeTwoList(Node head1, Node head2) { //       
    if (head1 == null && head2 == null) {
	return null;
    }
    if (head1 == null) {
	return head2;
    }
    if (head2 == null) {
	return head1;
    } //       
    Node head = null;
    if (head1.data > head2.data) { //  head         
	head = head2; //     head2
	head.next = mergeTwoList(head1, head2.next);
    } else {
	head = head1;
	head.next = mergeTwoList(head1.next, head2);
    }
    return head;
}