Answer:
#include <iostream>
#include <vector>
using namespace std;
void swapFrontBack(vector<int>& nums) {
if(nums.size() < 2) {
return;
}
swap(nums[0], nums[nums.size()-1]);
}
void printit(vector<int>& arr) {
for(int i = 0; i < arr.size(); i++) {
cout << arr[i] << " ";
}
cout << endl;
}
int main() {
vector<int> num1;
swapFrontBack(num1);
printit(num1);
num1.push_back(1);
swapFrontBack(num1);
printit(num1);
num1.push_back(2);
swapFrontBack(num1);
printit(num1);
vector<int> num2(10, 1);
num2[9] = 2;
swapFrontBack(num2);
printit(num2);
return 0;
}
Step-by-step explanation: