zoukankan      html  css  js  c++  java
  • 快速排序法

    #include <iostream>
    using namespace std;
    void quick_sort(int s[], int low, int high);
    
    void quick_sort(int s[], int low, int high)
    {
        if(low < high)
        {
            int i = low, j = high, key = s[low];
            while (i < j )
            {
                while(i < j && s[j] >= key) 
                --j;  
                if(i < j) 
                    s[i] = s[j];
                    
                while(i < j && s[i] <= key) 
                ++i;
                if(i < j) 
                    s[j] = s[i];
            }
            s[i] = key;
            quick_sort(s, low, i - 1);
            quick_sort(s, i + 1, high);
        }
    }
    int main()
    {
        int i,a[] = {1,100,4,6,2,7,87,22,11,34,65,78,9,99};
        quick_sort(a,0,sizeof(a)/sizeof(a[0])-1);  //sizeof(a)/sizeof(a[0]) 数组元素个数
        cout << "快速排序法:" << endl;
        for(i = 0; i<sizeof(a)/sizeof(a[0]); i++)
            cout << a[i] << " " ;
        return 0;
    }
  • 相关阅读:
    双击返回 退出程序
    读取InputStream 中的内容
    wsgi服务器
    python 中的GIL
    json
    __getattr__
    错误类型
    __slot__用法
    获取属性以及基本方法
    linux IO
  • 原文地址:https://www.cnblogs.com/ht-beyond/p/4157795.html
Copyright © 2011-2022 走看看