shift element to end of vector c 2b 2b

Solutions on MaxInterview for shift element to end of vector c 2b 2b by the best coders in the world

showing results for - "shift element to end of vector c 2b 2b"
Manel
17 Jan 2017
1template <typename t> void move(std::vector<t>& v, size_t oldIndex, size_t newIndex)
2{
3    if (oldIndex > newIndex)
4        std::rotate(v.rend() - oldIndex - 1, v.rend() - oldIndex, v.rend() - newIndex);
5    else        
6        std::rotate(v.begin() + oldIndex, v.begin() + oldIndex + 1, v.begin() + newIndex + 1);
7}
8
9auto initial_pos = 1;
10auto final_pos = 4;
11move(some_vector, initial_pos, final_pos);