w.rdc.sae.sina.com.cn:3307|nj41yyozkz|nj41yyozkz 范围数据原地排序,最坏复杂度2N « SAE云计算
Twitter FaceBook
Home
Sina App Engine
illuminati
illuminati
Posted by kobe, and filed under 计算机应用

int SelfSort(vector<int>& vec)
{
int loop_number=0;
for(int i=vec.size()-1;i>=1;)
    {
     loop_number++;
     if(vec[i]<i)
        swap(vec[i],vec[vec[i]]);
     else
        i–;
    }
return loop_number;
}

int main(int argc,char* agrv[])
{
srand(time(NULL));
vector<int> vec;
for(int i=0;i<1000;i++)
     vec.push_back(i);
random_shuffle(vec.begin(),vec.end(),p_myrandom);
cout<<SelfSort(vec)<<endl;
return 0;
}

13th 四 2010
illuminati

Leave a Reply

 
Designed by