编辑代码

#include <iostream>
using namespace std;
int n = 10;
void ShellInsert(int a[],int dk){
    for(int i=dk+1;i<=n;i++){
        if(a[i]<a[i-dk]){
            a[0] = a[i];
            int j;
            for(j=i-dk;j>0&&a[0]<a[j];j-=dk)
                a[j+dk] = a[j];
            a[j+dk] = a[0];
        }
    }
}
void Shellsort(int a[],int d[],int t){
    for(int k=0;k<t;k++)
        ShellInsert(a,d[k]);
}
void bullsort(int a[]){
    int flag = 1;
    int i=n-1;
    while(i>0&&flag==1){
        flag = 0;
        for(int j=1;j<=i;j++){
            if(a[j]>a[j+1]){
                flag = 1;
                a[0] = a[j+1];
                a[j+1] = a[j];
                a[j] = a[0];
            }
        }
        i--;
    }
}
int qsort(int a[],int low,int high);
void QSort(int a[],int low,int high)
{
    if(low<high){
        int p;
        p = qsort(a,low,high);
        QSort(a,low,p-1);
        QSort(a,p+1,high);
    }
}
int qsort(int a[],int low,int high){
    a[0] = a[low];
    while(low<high){
        while(low<high&&a[high]>=a[0])
            high--;
        //cout<<high;
        a[low] = a[high];
        while(low<high&&a[low]<=a[0])
            low++;
        //cout<<low<<endl;
        a[high] = a[low];
    }
    a[low] = a[0];
    return low;
}
int main() {
    int a[11]={0,49,38,65,97,76,13,27,49,55,4};
    int d[3] = {5,3,1};
    //Shellsort(a,d,3);
    //bullsort(a);
    //qsort(a,1,10)<<endl;
    QSort(a,1,10);
    for(int i=1;i<=10;i++)
        cout<<a[i]<<endl;
    return 0;
}