swap values vector c++ code example
Example 1: swap two elements of a vector
std::iter_swap(arr.begin()+pos1,arr.begin()+pos2);
Example 2: C++ Vector swap syntax
vector<T>().swap(x); // clear x reallocating
std::iter_swap(arr.begin()+pos1,arr.begin()+pos2);
vector<T>().swap(x); // clear x reallocating