链表快排


https://blog.csdn.net/otuhacker/article/details/10366563

每次是小数的最后一个,然后用的next位置进行的交换,如果第二个数比第一个数小,就相当于第二数和自己进行交换

链表只能从前往后

pNode* partition(pNode* start,pNode* end){
    int num = start->val;
    pNode* p = start;
    pNode* q = start->next;
    while(q != end){
        if(q->val < num){
            p = p->next;
            swap(p->val,q->val);
        }
        q = q->next;
    }
    swap(p->val,start->val);
    return p;
}


void quick_sort(pNode* start,pNode* end){
    if(start != end){
        pNode* index = partition(start,end);
        quick_sort(start,index);
        quick_sort(index->next,end);
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM