define a function swapfrontend() that has an integer vector parameter passed by reference, and swaps the first and last elements of the vector parameter. the function does not return any value.

Respuesta :

Answer:

#include <iostream>

#include <vector>

using namespace std;

void swapfrontend(vector<int> &v)

{

  int temp = v[0];

  v[0] = v[v.size() - 1];

  v[v.size() - 1] = temp;

}

int main()

{

  vector<int> v;

  int num;

  cout << "Enter numbers to be inserted in the vector, then enter -1 to stop.\n";

  cin >> num;

  while (num != -1)

  {

     v.push_back(num);

     cin >> num;

  }

  swapfrontend(v);

  cout << "Here are the values in the vector:\n";

  for (int i = 0; i < v.size(); i++)

     cout << v[i] << endl;

  return 0;

}