Why is the code not working


#1

ListNode* Solution::partition(ListNode* A, int B) {
ListNode *a,*b;
a=A;
if(a==NULL||a->next==NULL){
return a;
}
int temp;
b=a->next;
while(b!=NULL&&a!=NULL){
if(a->val>B){
while(b->val>=B){
b=b->next;
if(b==NULL)
return A;
}
temp=a->val;
a->val=b->val;
b->val=temp;
}
a=a->next;
b=b->next;
}
return A;
}