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
When describing memory, ____________ is the first component required in the process necessary for retention?
8_murik_8 [283]
Depends on how deep you're willing to go to really,
You need one of a few arrangements of flip flop circuits to keep 1-bit state.
Going deeper, you need either NAND, or NOR gates(or a bunch of other ones) and connectors.
Even deeper, you'll require diodes or transistors to build the logic gates.
Beyond that is particle physics.
8 0
3 years ago
After earning a learners license what test must be successfully passed to earn an operators license in Florida
Monica [59]
After earning a learners license , the <span>test that must be successfully passed to earn an operators license in Florida is: the driving skill test
The diriving skill test is a set of procedure that all learners must follow in order to determine the learners' ability in driving motor vehicle and test learner's understanding about traffic rules.</span>
5 0
3 years ago
Which of the following formats allow visual, video, and sound capability and can be uploaded to certain social networking sites?
insens350 [35]
It is Microsoft work
This is because
6 0
3 years ago
Which of the following is not true of client-server applications?
Sliva [168]

Answer:

B.

Explanation:

Client-server application is a relationship between a client and a server.

In this relationship, the client (a program) requests a service from the server (the other resource).

The statement that is not true about the client-server applications is they include smart phones, tablets, iPads, laptops, desktop computers.

Rest of the statements concerning client-server relationship are true.

Therefore, option B is the answer.

3 0
3 years ago
Please help me i will award brainliest
Sergio [31]

Answer: It would be option C.

Explanation: The file name is invalid, so therefore it would make sense to rename the most recent version correctly.

8 0
3 years ago
Other questions:
  • Laws differ from theories because laws do not provide
    13·1 answer
  • I have been trying to work on this for a while now, and this is on excel
    11·1 answer
  • But this time use 16 kib pages instead of 4 kib pages. what would be some of the advantages of having a larger page size? what a
    11·1 answer
  • _______ are special incentives or excitement-building programs that encourage consumers to purchase a particular product, often
    7·1 answer
  • If we are using an 4-character password that contains only lowercase English alphabetic characters (26 different characters), ho
    15·2 answers
  • What might happen if the internet use policies were broken at your school
    11·2 answers
  • ppose we have a Rectangle class that includes length and width attributes, of type int, both set by the constructor. Define an e
    9·1 answer
  • Which of these is an expansion slot type?
    5·1 answer
  • I need help about computer program. Solve C language code...... please​
    7·1 answer
  • What are some limitations when it comes to testing and ensuring program quality? List at
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!