zoukankan      html  css  js  c++  java
  • Quick Sort

    #include <iostream>
    using namespace std;
    
    void QuickSortCore(int a[], int start, int end)
    {
        if (start > end)
            return;
        int key = a[start];
        int blank = start;
        int left = start + 1;
        int right = end;
    
        while(left <= right){//维护left right blank key
            if (blank < left){
                if (key <= a[right]){
                    right--;
                    continue;
                }
                else{
                    a[blank] = a[right];
                    blank = right--;
                    continue;
                }
            }
            else if (blank > right){
                if (key >= a[left]){
                    left++;
                    continue;
                }
                else{
                    a[blank] = a[left];
                    blank = left++;
                    continue;
                }
            }
        }
        a[blank] = key;
    
        QuickSortCore(a, start, blank - 1);
        QuickSortCore(a, blank + 1, end);
    }
    
    void QuickSort(int a[], int len){
        if (!a || len < 0)
            return;
    
        QuickSortCore(a, 0, len-1);
    }
    
    
    int main()
    {
        int a[] = {3,6,5,81,94,53,0,12,4,2,4,2,1};
        QuickSort(a, 13);
        return 0;
    }

    EOF

  • 相关阅读:
    195
    194
    193
    192
    191
    190
    Oracle 11g使用rman从单实例迁移到RAC
    RESTful API 设计指南
    Oracle GoldenGate(OGG)- 超级详细
    【转】Oracle GoldenGate OGG管理员手册
  • 原文地址:https://www.cnblogs.com/lihaozy/p/2824303.html
Copyright © 2011-2022 走看看