STL之逆转和旋转

逆转

1.reverse()

reverse(ivec.begin(),ivec.end());   //123456转换成654321

2.reverse_copy()

reverse_copy(ivec.begin()+1,ivec.end()-1,ostream_iterator(cout," "));   

 //123456789 转换成8765432

旋转

1.rotate()

rotate(ivec.begin(),ivec.begin()+1,ivec.end());     //12345转换成23451

rotate(ivec.begin(),find(ivec.begin(),ivec.end(),4),ivec.end());   //12345转换成45123

2.rotate_copy()

rotate_copy(iset.begin(),iset.begin()+1,iset.end(),ostream_iterator(cout," "));

// 12345转换成23451

rotate_copy(iset.begin(),iset.find(4),iset.end(),ostream_iterator(cout," "));  //set中有find的成员函数,把找到的4作为头进行旋转

//12345转换成45123

你可能感兴趣的:(STL之逆转和旋转)