swap elements of vector

Apr 21, 2014 at 12:01am
hello, i need to learn how to swap the first and 'mid' elements of a vector? can anybody help?

Apr 21, 2014 at 12:13am
Find the size of the vector and once you have that, find the middle number (what are you supposed to do if the vector size is an even number and there are two middle elements?). Then swap this number with the first. <vector> already has functions to find the size and swap elements can be done by just copying the values to some place else then inserting them back in appropriate places afterwards - http://www.cplusplus.com/reference/vector/vector/

Last edited on Apr 21, 2014 at 12:14am
Apr 21, 2014 at 12:17am
im trying to figure out how to use this 'swap' function. it sounds like it swaps elements of two different vectors, and now to elements that are inside of the same vector? or maybe im just not understanding
Topic archived. No new replies allowed.