public static void reverse_n (ListNode n0, int n) {//passed
        ListNode temphead = n0;
        ListNode p_prev = temphead;
        ListNode p;
        ListNode lasttail = new ListNode(0);
        ListNode head = null;
        int m = 3;
        for (int j = 0; j < m; ++j) {
            //int n = 2;
            for (int i = 0; i < n-1 && p_prev.next != null; ++i) {
                p = p_prev.next;
                p_prev.next = p.next;
                p.next = temphead;
                temphead = p;
            }
            lasttail.next = temphead;//concatenate the previous sublist with current sublist
            lasttail = p_prev;//points to the tail of current sublist
            p_prev = p_prev.next;
            if (j == 0) head = temphead;//get the genuine head
            temphead = p_prev;
        }
        //print the list
        ListNode temp = head;
        while (temp != null) {
            System.out.println(temp.val);
            temp = temp.next;
        }
    }