Question: C++ Program..... Write a function SwapVectorEnds() that swaps the first and last elements of its vector parameter. Ex: sortVector = {10, 20, 30, 40} becomes

C++ Program.....

Write a function SwapVectorEnds() that swaps the first and last elements of its vector parameter. Ex: sortVector = {10, 20, 30, 40} becomes {40, 20, 30, 10}. The vector's size may differ from 4.

#include #include using namespace std;

/* Your solution goes here */

int main() { vector sortVector(4); int i = 0;

sortVector.at(0) = 10; sortVector.at(1) = 20; sortVector.at(2) = 30; sortVector.at(3) = 40;

SwapVectorEnds(sortVector);

for (i = 0; i < sortVector.size(); ++i) { cout << sortVector.at(i) << " "; } cout << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!