BubbleSort(C)

void BubbleSort( int * Array,int length )
{
    assert( Array != NULL && length>0 );
    bool bNoswap = false;
    int i = length-1;
    int j = 0;
    int tempswap = 0;
    for ( ;i>0;i-- )
    {
        bNoswap = true;
        for ( j=0;j<i;j++ )
        {
            if ( Array[j]>Array[j+1] )
            {
                bNoswap = false;
                tempswap = Array[j];
                Array[j] = Array[j+1];
                Array[j+1] = tempswap;
            }
        }
        if ( bNoswap == true )
        {
            return;
        }
    }
}

 

posted @ 2013-05-07 21:19  zhouyoulie  阅读(195)  评论(0)    收藏  举报