#include <iostream>
using std::cin;
using std::cout;
#include <vector>
using std::vector;
#include <algorithm>
using std::swap;

/*5. Write two functions that reverse the order of elements in a vector<int>.
For example, 1, 3, 5, 7, 9 becomes 9, 7, 5, 3, 1. The first reverse function 
should produce a new vector with the reversed sequence, leaving its original vector 
unchanged. The other reverse function should reverse the elements of its vector 
without using any other vectors (hint: swap).
*/


vector<int> reverse01(vector<int>& v) {
	vector<int> newv;
	for (unsigned i = v.size(); i > 0; i--) {
		newv.push_back(v[i-1]);
	}
	return newv;
}

vector<int> reverse02(vector<int>& v) {
	for (unsigned i = 0; i < v.size() / 2; i++) {
		swap(v[i], v[v.size() - 1 - i]);
	}
	return v;

}

int main() {
	vector<int> v{ 1,3,5,7,9 }, w;
	w = reverse01(v);
	for (int i : w) cout << i << " ";
	cout << '\n';
	reverse02(v);
	for (int i : v) cout << i << " ";
	std::reverse(w.begin(), w.end());
	cout << '\n';
	for (int i : w) cout << i << " ";
	cin.get();
}