Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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

PREVIOUS NEXT
Code Example
:: new in c++ 
::  
Cpp ::  
::  
::  
::  
Cpp ::  
Cpp ::  
::  
::  
::  
::  
Cpp ::  
Cpp :: lcm in c++ 
::  
::  
::  
:: full pyramid in c++ 
Cpp ::  
::  
:: find min and max in array c++ 
::  
::  
::  
Cpp ::  
::  
::  
Cpp ::  
::  
::  
ADD CONTENT
Topic
Content
Source link
Name
9+6 =