关于#c++单链表#的问题,请各位专家解答!问题写在了单行注释里

描述
将一个节点数为 size 链表 m 位置到 n 位置之间的区间反转,要求时间复杂度 O(n)O(n),空间复杂度 O(1)O(1)。
例如:

给出的链表为 1→2→3→4→5→NULL, m=2,n=4m=2,n=4,
返回 1→4→3→2→5→NULL.

数据范围: 链表长度 0 < size \le 10000<size≤1000,0 < m \le n \le size0<m≤n≤size,链表中每个节点的值满足 |val| \le 1000∣val∣≤1000
要求:时间复杂度 O(n)O(n) ,空间复杂度 O(n)O(n)
进阶:时间复杂度 O(n)O(n),空间复杂度 O(1)O(1)
示例1
输入:
{1,2,3,4,5},2,4

返回值:
{1,4,3,2,5}

/**
 * struct ListNode {
 *    int val;
 *    struct ListNode *next;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param head ListNode类 
     * @param m int整型 
     * @param n int整型 
     * @return ListNode类
     */
    ListNode* reverseBetween(ListNode* head, int m, int n) {
        // write code here
        ListNode* res=new ListNode(-1);
        res->next=head;
        ListNode* pre=res;
        ListNode* cur=head;
        for(int i=1;i<m;i++) {
            pre=cur;
            cur=cur->next;
        }
        for(int i=m;i<n;i++) {
            ListNode* temp=cur->next;
            cur->next=temp->next;
            temp->next=pre->next;//我的疑问是为什么这里不能写为temp->next=cur?
            pre->next=temp;
        }
        return res->next;
        
    }
};

temp->next=pre->next;//我的疑问是为什么这里不能写为temp->next=cur?

img