C++ solution using link change


#1

Below is the Solution which can be applied in any version of the questions by changing node links.

 ListNode* dummy0=new ListNode(2);
    ListNode* dummy1=new ListNode(3);
    ListNode* prev=dummy0,*curr=A;
    ListNode* temp1=dummy1;
    while(curr!=NULL){
        if(curr->val==1){
            temp1->next=curr;
            temp1=temp1->next;
        }
        else{
            prev->next=curr;
            prev=prev->next;
        }
         curr=curr->next;
    }
    prev->next=dummy1->next;
    temp1->next=NULL;
    return dummy0->next;