将Vector的第一个元素移至最后一个元素 [英] Move first element of Vector to last element
本文介绍了将Vector的第一个元素移至最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此后应该是这样的
v = {2,3,4,1}
我的编译器版本是gcc版本4.4.3(Ubuntu 4.4.3-4ubuntu5.1)
我知道在Vc11中我们可以使用std :: move来移动元素。但是我怎么能在上述版本的编译器中做到这一点?
标准库中的cppreference.com/w/cpp/algorithm/rotaterel =nofollow> std :: rotate
算法: std :: rotate(ObjectToRotate.begin(),
ObjectToRotate.end() - 1,//这将是新的第一个元素
ObjectToRotate.end());
I want to move first element of vector to the end of vector.
v = {1,2,3,4} after this should be like this
v= {2,3,4,1}
my compiler version is gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
I know in Vc11 we can use std::move to move element. but how can I do this in above version of compiler?
解决方案
There's a std::rotate
algorithm in the standard library:
std::rotate(ObjectToRotate.begin(),
ObjectToRotate.end()-1, // this will be the new first element
ObjectToRotate.end());
这篇关于将Vector的第一个元素移至最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文