What is wrong with my code? #C++


#1

/**

  • Definition for singly-linked list.
  • struct ListNode {
  • int val;
    
  • ListNode *next;
    
  • ListNode(int x) : val(x), next(NULL) {}
    
  • };
    /
    ListNode
    Solution::reverseBetween(ListNode* A, int B, int C) {
    ListNode *ptr1=A,*ptr2=A;
    for(int i=0;i<B-1;i++){
    ptr1=ptr1->next;
    }
    for(int i=0;i<C;i++){
    ptr2=ptr2->next;
    }
    ListNode *prev=ptr2,*n;
    while(ptr1!=ptr2){
    n=ptr1->next;
    ptr1->next=prev;
    prev=ptr1;
    ptr1=n;
    }
    ListNode *ptr3=A;
    for(int i=0;i<B-1;i++){
    ptr3=ptr3->next;
    }
    ptr3=prev;
    return A;
    }