Horje
shift element to end of vector c++ Code Example
shift element to end of vector c++
template <typename t> void move(std::vector<t>& 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);




Cpp

Related
nested conditional operator Code Example nested conditional operator Code Example
stoi cpp Code Example stoi cpp Code Example
Youtube Video Downloder Website Code Example Youtube Video Downloder Website Code Example
how to pass std::array with unknown size to function C++ Code Example how to pass std::array with unknown size to function C++ Code Example
unordered map c++ Code Example unordered map c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
14