Confused how to sort the right part!!


  • 0
    H
    ListNode *current = head , *pivot = head , *prev = head,*oldPivot = NULL;
    if(current == NULL || current->next == NULL)
        return current;
        
    current = pivot->next;
    
    while(oldPivot != pivot ){
        if(pivot->val > current->val){
            prev->next = current->next;
            current->next = head;// 
            head = current;
            current = prev->next;
    } else {
        current = current->next;
        prev = prev->next;
    }
    if(current == NULL || current == oldPivot){
        current = head->next;
        prev = head;           
        oldPivot = pivot;
        pivot = head;
    }
    }
    return head;
    

    Any idea how can I proceed with the right part as well. Currently my code is sorting only the left sub linked list!!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.