1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Montano1993 [528]
2 years ago
9

Write a function named swapFrontBack that takes as input a vector of integers. The function should swap the first element in the

vector with the last element in the vector. The function should check if the vector is empty to prevent errors. Test your function with vectors of different length and with varying front and back numbers.
Computers and Technology
1 answer:
kondaur [170]2 years ago
4 0

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;

}

Explanation:

You might be interested in
True or false webcasts are delivered only as prerecorded audio and video content
alexandr1967 [171]
I believe the answer is false
3 0
3 years ago
A(n) __________ window is an open window hidden from view but that can be displayed quickly by clicking the window's program but
Alex787 [66]
Minimized window

The sign to click is a "-" sign (minus)
4 0
3 years ago
Care should be taken whenever you post comments or photos to any social media or other websites, because each of these online ac
REY [17]

Answer:

True

Explanation:

Building your personal brand requires extreme care when it comes to social media presence. In the age of internet there is nothing hidden, so whatever you post or comment will be seen by your audience and it can go in either way. It can either make your brand or break it. It is of utmost importance to leave a pleasant and positive impact on your audience. One should not indulge in inappropriate or controversial debates and try to avoid being too personal on social media.  

6 0
3 years ago
Help guys thank you =) ​
MrRissso [65]
1.LR
2.LR
3.HR
4.LR
5.HR
6 0
2 years ago
Who sang devil went down to georgia
katrin2010 [14]

Answer:

Charlie Daniels sang that one for sure

4 0
3 years ago
Other questions:
  • Carlos owns a hardware store. He currently is not using any software to track what he has in the store. In one to two sentences,
    9·2 answers
  • Write a MIPS assembly language program that prompts for a user to enter how many floating point numbers to enter, then prompts t
    10·1 answer
  • If you want to import text into a DTP application that was first created in a word processing program, what must you do?
    9·2 answers
  • A self-confident person knows that:
    13·1 answer
  • Which key should you press to leave the cell as it originally was?
    15·1 answer
  • When you align or size a group of selected controls, the changes are made relative to the
    14·1 answer
  • Help me with this please
    5·1 answer
  • Is this App for real?​
    5·1 answer
  • Which of the following is not a key component of a structure?
    12·1 answer
  • What is the top 3 cloud provider in the world with statics or data including the example and reason(s).
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!