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
Frankie used the ps command to find the process id of an application that he needs to stop. What command-line tool should he use
ASHA 777 [7]

In the case above, the command-line tool should he use to stop the application based on its process id is e option

What is the use of ps command?

The ps command is known to be one that helps enables a person to be able to look at the status of any kind of active processes on a system, and also that of display technical information in regards to the processes.

Note that In the case above, the command-line tool should he use to stop the application based on its process id is e option

Learn more about command-line tool from

brainly.com/question/3737699

#SPJ1

7 0
2 years ago
You want to discard your old computer and want to securely erase the data from your hard drive. What can you use to do this and
qwelly [4]
Go here this should help bunches!
http://www.microsoft.com/security/online-privacy/safely-dispose-computers-and-devices.aspx
Hope this website helps!
5 0
3 years ago
What is the answer to this?
Anit [1.1K]

Answer: I think the Valorous Unit Ribbon

Explanation: I don't really understand what's it asking but I sort of did to get this answer!

5 0
3 years ago
Mary, Tim, John, and Jenn each sold three million dollars worth of product within six months. Each month one of them was awarded
photoshop1234 [79]

if its the same chart im looking at on this page, the answer is john.

5 0
3 years ago
Read 2 more answers
Which agricultural CTSO has programs for middle-school and high-school students, as well as college students?
Airida [17]
National FFA is the answer to your question my guy.
4 0
3 years ago
Read 2 more answers
Other questions:
  • Why would an over the shoulder shot be used
    11·1 answer
  • This activity will help you meet these educational goals:
    7·2 answers
  • The Microsoft-NanoServer-Guest-Package installs the drivers necessary for installing Nano Server as a host OS on a physical mach
    15·1 answer
  • What type of analysis should be used to respond to the statement, "Let's cut advertising by $1000 repeatedly so we can see its r
    14·1 answer
  • What is the first step that you have to perform before you can add a windows package to a wim file?
    9·1 answer
  • If you need some one to talk to you can talk to me
    13·2 answers
  • PLEASE I NEED HELP FAST
    8·1 answer
  • Your project will require a 7-day work week rather than the traditional 5-day. How can you adapt the software to this new schedu
    15·1 answer
  • Which user interface part shows graphical output of mined data?
    8·2 answers
  • Most of the energy we use originally came from:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!