排序集合

BubbleSort

void BubbleSort(T V[],int n){
    for(int i;i<n;i++)
        for(int j=n-1;j>i;j--)
    if(V[j-1]>V[j]){
        T temp=V[j-1];
        V[j-1]=V[j];
        V[j]=temp;
    }
}

改进版BubbleSort

void BubbleSort(T V[],int n)
{
    bool exchange;
    for(int i; i<n; i++)
    {
        exchange=false;
        for(int j=n-1; j>i; j--)
            if(V[j-1]>V[j])
            {
                T temp=V[j-1];
                V[j-1]=V[j];
                V[j]=temp;
                exchange=true;
            }
        if(exchange==false)
            return ;
    }
}
原文地址:https://www.cnblogs.com/wangjianupc/p/10587203.html