Exemplo n.º 1
0
void quikSort(int a[],int low,int high)
{
    if(low < high)
    {
        int pos = onceSort(a,low,high);
        quikSort(a,low,pos - 1);
        quikSort(a,pos + 1,high);
    }
}
Exemplo n.º 2
0
int main()
{
    int  a[] = {11,99,11,20,0,21,3,1,6,18,4,10};
    quikSort(a,0,11);
    for(int i=0;i<12;i++)
        std::cout<<a[i]<<" ";
    return 0;
}
Exemplo n.º 3
0
int main(void)
{
    int a[] = {3,2,7,6,9,8,5,4,1};
    quikSort(a,0,8);

    for(int i = 0; i < 9; i++)
    {
        std::cout<<a[i]<<" ";
    }
    std::cout<<std::endl;
    return 0;
}
Exemplo n.º 4
0
void quikSort(int a[],int first,int end){
    int i=first,j=end;
    int temp=a[first];
    while(i<j){
        while(i<j && a[j]>=temp){
            j--;
        }
        while(i<j && a[i]<=temp){
            i++;
        } 
        std::swap(a[i],a[j]);
    }
    std::swap(a[first],a[i]);

    if(first<i-1){
        quikSort(a,first,i-1);
    }
    if(end>i+1){
        quikSort(a,i+1,end);
    }
}
Exemplo n.º 5
0
int  main(int argc, char const *argv[])
{
    /* code */
    //int a[9]={1,56,12,53,7,-9.100,20,2};
    srand(unsigned(time(NULL)));
    int a[9];
    for (int i = 0; i < 9; ++i)
    {
        /* code */
        a[i] = random()%1000;
    }
    quikSort(a,0,8);
    for (int i = 0; i < 9; ++i)
    {
        /* code */
        std::cout<<a[i]<<" ";
    }
    return 0;
}