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
Francis works in the human resources division of a large oil and gas company in Texas. Francis' tasks include maintaining payrol
KiRa [710]

Answer: Information MIS infrastructure

Explanation: Information MIS infrastructure is the company model that is used for supporting the task functioning . The main aim of this tool is to be used in backing -up , plan of diasater recovery and plan of business continuity.

These objectives are achieved by availability, portability , scalability , accessibility, maintainability etc characteristic. Francis is also involved in information MIS infrastructure by maintaining the payroll, records,history of employment  etc, securing the information,etc.

4 0
4 years ago
It is best to say that electric motors require _______ to work.
Mila [183]
Electricity (energy, current, power, voltage ... depending on the context)
4 0
3 years ago
Write a java program.
Sliva [168]

Answer:

The source code has been attached to this response. It contains comments explaining each line of the code. Kindly go through the comments.

To run this program, ensure that the file is saved as ArithmeticProcessor.java

Keep editing line 7 of the code to test for other inputs and arithmetic operation.

A sample output has also been attached to this response.

6 0
3 years ago
What is HTML?
krok68 [10]

the answer is C. a website.


hope this helps!

6 0
3 years ago
Read 2 more answers
Why dose enginuty suck like really
masya89 [10]

Answer:

if you don't like it why u doin it?

Explanation:

3 0
3 years ago
Other questions:
  • In the Remote Access Domain, if private data or confidential data is compromised remotely, you should set automatic blocking for
    5·1 answer
  • The following algorithm should output the t times table in the format:
    6·1 answer
  • What is cpu????????????????????????????
    12·2 answers
  • What is a core in computer
    11·2 answers
  • How do you launch windows on a computer?
    14·1 answer
  • _ models are non visual ways of communicating how someone thinks about something in the natural world
    12·1 answer
  • What sort of query is (strbucks]?
    14·1 answer
  • Why are Quick Parts useful in an Outlook message?
    5·1 answer
  • A global clothing company is looking to create a more immersive shopping experience for customers.What is a way the company can
    14·2 answers
  • The __________ algorithm takes the ciphertext and the secret key and produces the original plaintext
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!