Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move first element of Vector to last element

Tags:

c++

gcc

move

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?

like image 664
Muhammad Zaighum Avatar asked Oct 27 '25 23:10

Muhammad Zaighum


1 Answers

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());

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!