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
/* Your solution goes here */
int main() { vector
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
Get step-by-step solutions from verified subject matter experts
