rotate(intVect2.begin(),intVect2.begin()+6,intVect2.begin()+6);这一句又作何解释?#include<iostream>#include<cstdlib>#include<vector>#include<algorithm>using namespace std;/pedeftypedef int I;typedef char C;/pedeftypedef int I;typedef char C;//宏定义#define N 3#define X(a,b) (((a)+(b))*3)//自定义函数声明void f1();void output(I);//主函数int main(int argc,char * argv[]){ f1(); cout<<endl; cout<<argc<<ends<<* argv<<endl; system("pause"); return 0;}//自定义函数void f1(){ //定义vector对象 vector<I> intVect1,intVect2; //push_back intVect1.push_back(0); intVect1.push_back(1); intVect1.push_back(2); intVect1.push_back(3); intVect1.push_back(4); intVect1.push_back(5); intVect1.push_back(6); intVect1.push_back(7); intVect1.push_back(8); intVect1.push_back(9); intVect2.push_back(0); intVect2.push_back(1); intVect2.push_back(2); intVect2.push_back(3); intVect2.push_back(4); intVect2.push_back(5); intVect2.push_back(6); intVect2.push_back(7); intVect2.push_back(8); intVect2.push_back(9); cout<<"Vect1:"<<endl; //for_each() for_each(intVect1.begin(),intVect1.end(),output); cout<<endl; //rotate rotate(intVect1.begin(),intVect1.begin()+6,intVect1.end()); cout<<"new Vect1:"<<endl; //for_each() for_each(intVect1.begin(),intVect1.end(),output); cout<<endl<<endl; cout<<"Vect2:"<<endl; //for_each() for_each(intVect2.begin(),intVect2.end(),output); cout<<endl; //rotate rotate(intVect2.begin(),intVect2.begin()+6,intVect2.begin()+6); cout<<"new Vect1:"<<endl; //for_each() for_each(intVect1.begin(),intVect1.end(),output); cout<<endl;}void output(I x){ cout<<x<<ends;}
1 回答
SMILET
TA贡献1796条经验 获得超4个赞
rotate其实就可以看做是一个循环移位的函数,比如将串“ABCDEFG”以D为中心旋转,就相当将该串向左循环移位,直到元素为D为止,最后得到新串“DEFGABC”。以上就解释了你所遇到的问题,重要的是第二个参数,要比第三个小,以第二个参数为中心
- 1 回答
- 0 关注
- 155 浏览
添加回答
举报
0/150
提交
取消