Any sort of implementations are welcomed :)


#1

typedef ListNode* ptr;
ListNode* Solution::partition(ListNode* A, int B) {
ptr t1=A,t2=A;
while(t2!=NULL)
{
if(t2->val >=B)
{
break;
}
t1=t2;
t2=t2->next;
}
if(t2->next==NULL) return A;
ptr m1,m2,c;
m2=t2->next;
m1=t2;

while(m2!=NULL)
{
    if(m2->val<B)
    {
        c=m2->next;
        m1->next=m2->next;
        m2->next=t2;
        if(t2==A)
        {
            A=m2;
            t2=A->next;
            t1=A;
            m2=c;
            continue;
        }
        t1->next=m2;
        t1=m2;
        m2=c;
    }
    else 
    {
        m1=m2;
        m2=m2->next;
    }
    
}
return A;

}


#2

and yeah, the solution provided in the answer is far better