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
The first step when entering data is _
34kurt

Answer:

click on the cell

Explanation:

This is a little tricky. We need to first think of the column, then of row, and then click on the corresponding cell. And then we either start typing or move our mouse to highlight the cells. Hence, the correct option here is click on the cell.

3 0
2 years ago
If an M:N relationship is mandatory on both sides, and if both relations resulting from the entities involved in the relationshi
vivado [14]

Answer:

0

Explanation:

In the problem above, the relationship that exists between M and N is discovered to be on each side of the system. Furthermore, it was stated that the outcome of the relationship also has approximately 3 records. This shows that there is no record for the bridge that is formed as a result of the relationship.

4 0
3 years ago
Why is iot architecture important?
Harlamova29_29 [7]
They need to make sure your building is easy to move around in. Beyond the building itself, architecture and design can help bring balance to people's lives. ... Well-designed schools create better learning environments. Workplaces with good architecture experience higher productivity.
7 0
3 years ago
Which AWS service is a managed service that makes it easy to set up, operate, and scale a relational database in the cloud?​
vaieri [72.5K]

Answer:

I use Google cloud free tier for my Minecraft server

4 0
3 years ago
Pathways in the Science, Technology, Engineering, &amp; Mathematics Career Cluster include:
ZanzabumX [31]

Answer: wanna say engineering technology and science and mathematics

Explanation:

7 0
3 years ago
Other questions:
  • Consider the following recursive method, which is intended to return a String with any consecutive duplicate characters removed.
    11·1 answer
  • What is the Multiplier if the change in RGDP is $525,000,000 and initial spending is $100,000?
    12·1 answer
  • Explain which are of the brain you think might light up to show that you are telling a lie and why
    10·1 answer
  • What document type would be best to communicate sales items from a business to potential customer?
    12·1 answer
  • Which one of these do not belong on the Do's list in Helpful Hints when preparing a presentation: Which one of these do not belo
    8·1 answer
  • An administrator has noticed that GPO containing new update settings has not yet applied to one of the computers on the network.
    5·1 answer
  • Check examples of a good work ethic. *
    6·1 answer
  • There are....... section in<br>cpu<br>​
    15·1 answer
  • Tell the story, step by step, of how your computer finds the CodeHS server,
    9·1 answer
  • Budgeting for a Computer
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!