zoukankan      html  css  js  c++  java
  • 单链表的快排

    /*
        Author:cavehubiao
        Mail:cavehubiao@qq.com
        MyBlog:http//www.cnblogs.com/cavehubiao
    */
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<ctime>
    using namespace std;
    
    struct st
    {
        st* next;
        int value;
        st(int va,st* p=NULL):value(va),next(p){
        }
    };
    
    void lqsort(st*left,st*right)
    {
        if(left!=right)
        {
            st* slow=left;
            st* fast=left->next;
            
            for(;fast!=right;fast=fast->next)
            {
                if(fast->value<=left->value)
                {
                    slow=slow->next;
                    swap(slow->value,fast->value);
                }
            }
            //slow=slow->next;
            swap(slow->value,left->value);
            
            lqsort(left,slow);
            lqsort(slow->next,right);
        }
    }
    int main()
    {
        srand((unsigned)time(NULL));
        int len;
        cin>>len;
        
        st* List=NULL,*pre=NULL;
        for(int i=0;i<len;i++)
        {
            st* pnode=new st(rand()%1000);
            if(pre==NULL)
            {
                List=pnode;
                pre=pnode;
            }
            else
            {
                pre->next=pnode;
                pre=pnode;
            }
            
        }
        lqsort(List,NULL);
        
        for(int i=0;i<len;i++)
        {
            cout<<List->value<<' ';
            st* tmp=List;
            List=List->next;
            delete tmp;
        }
    
      return 0;
    }
  • 相关阅读:
    ruby安装方法
    移动端适配问题px->rem方法
    判断元素阶段类型
    domReady
    电梯导航
    判断浏览器的版本以及浏览器内核( 转发 )
    AWS
    Amazon S3
    Pipeline 模型
    RESTful API
  • 原文地址:https://www.cnblogs.com/cavehubiao/p/3679091.html
Copyright © 2011-2022 走看看