private static Node merge(Node head1, Node head2) {
        if (head1 == null) {
            return head2;
        } else if (head2 == null) {
            return head1;
        }
        Node node = null;
        Node head = null;
        while (head1 != null || head2 != null) {
            if (head1 == null) {
                node.next = head2;
                break;
            } else if (head2 == null) {
                node.next = head1;
                break;
            } else {
                Node nextNode;
                if (head1.value <= head2.value) {
                    nextNode = head1;
                    head1 = head1.next;
                } else {
                    nextNode = head2;
                    head2 = head2.next;
                }
                if (head == null) {
                    head = nextNode;
                } else {
                    node.next = nextNode;
                }
                node = nextNode;
            }
        }
        return head;
    }