vectors

1. Check if the size of the vector is odd or even with the std::vector::size member function.
http://www.cplusplus.com/reference/vector/vector/size/

2. Since vectors are zero-based, the same with arrays, the last element is the std::vector::size - 1 element. Push back into the vector the last element, duplicating the last element.
Duplicating the last vector element can be achieved using std::vector::end member function. It returns an iterator referring to the past-the-end element in the vector container.
http://www.cplusplus.com/reference/vector/vector/end/

Iterators are like pointers, you can use "pointer math" on the iterator. The last element in the vector is std::vector::end - 1.

Push back the dereferenced end iterator - 1.
Last edited on
What happened to the OP - another troll post removed........
Yeah, I thought that looked odd. Or maybe the OP just deleted his post...?
Topic archived. No new replies allowed.