[Solved] How to put an element from an array infront of another element.?
[ad_1] A generic, in-place solution might be: #include<vector> #include<cassert> #include<algorithm> // random iterator, the behaviour is undefined if first == second, or // first and second do not belong to some valid range template<typename RIter> void move_in_front_of( RIter first, RIter second ) { std::iter_swap(first,second); if( first < second ) std::rotate(std::next(first),second,std::next(second)); else std::rotate(std::next(second),first,std::next(first)); } int main() … Read more