📜  将元素移到向量的末尾 c++ 代码示例

📅  最后修改于: 2022-03-11 14:44:51.591000             🧑  作者: Mango

代码示例1
template  void move(std::vector& v, size_t oldIndex, size_t newIndex)
{
    if (oldIndex > newIndex)
        std::rotate(v.rend() - oldIndex - 1, v.rend() - oldIndex, v.rend() - newIndex);
    else        
        std::rotate(v.begin() + oldIndex, v.begin() + oldIndex + 1, v.begin() + newIndex + 1);
}

auto initial_pos = 1;
auto final_pos = 4;
move(some_vector, initial_pos, final_pos);