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
Cpp :: right shift in c++ 
Cpp :: Temparory Email Id 
Cpp :: why return 0 in int main 
Cpp :: nested conditional operator 
Cpp :: how to insert in a queue c++ 
Cpp :: find maximum sum of circular subarray 
Cpp :: c++ switch case 
Cpp :: tower of hanoi 
Cpp :: floor and ceil in cpp 
Cpp :: not c++ 
Cpp :: c++ initialize size of 3d vector 
Cpp :: bubble sort function in c++ 
Cpp :: c++ allocate dynamic with initial values 
Cpp :: Decision Making in C / C++ (if , if..else, Nested if, if-else-if ) 
Cpp :: Programming Languages codechef solution in c++ 
Cpp :: waiting in a serial as the spool reflect the queue operation. Demonstrate Printer Behavior in context of Queue.Subject to the Scenario implement the Pop and Push Using C++. 
Cpp :: c++ calling variable constructor 
Cpp :: remove item from layout 
Cpp :: use ster when declaring variables cpp 
Cpp :: whatsup 
Cpp :: How to remove the % in zsh that show after running c++ file 
Cpp :: can i delete a null pointer in c++ 
Cpp :: c++ Testing implementation details for automated assessment of sorting algorithms 
Cpp :: default parameter c++ a field 
Cpp :: how to install open cv2 in c++ on ubuntu 
Cpp :: Nested ternary operator C++ 
Cpp :: 1822. Sign of the Product of an Array leetcode 
Cpp :: ue4 c++ bool to text 
Cpp :: http://nv-study.ru/http://nv-study.ru/http://nv-study.ru/ 
Cpp :: matrix chainmultiplication 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =