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
What are the parts to an
bazaltina [42]

Answer:

B) recipient subject body signature

5 0
3 years ago
If name is a String instance variable, average is a double instance variable, and numOfStudents is a static int variable, why wo
IRINA_888 [86]

Answer:

a.

Explanation:

Based solely on the snippet of code provided on the question the main reason why the code won't compile (from the options provided) is that the setAverage() method can’t access the average instance variable. Since the average variable is an instance variable it means that it only exists inside the one of the functions and not to the entire class. Meaning that in this scenario it can only be accessed by the Student function and once that function finishes it no longer exists. Also, it is not one of the options but if these variables are instance variables as mentioned their type needs to be defined inside the function.

7 0
3 years ago
Helpppppppppppppphuhuh
Serga [27]

Answer:

B

Explanation:

You listed this as Computers and Technology where we post coding questions, or hardware related things, but ok.

If there is 7/8 jugs as the starting amount, and they have a 1/2 jug, dividing 0.875 by 0.5 gives the answer of 1.75 or 1 3/4.

3 0
3 years ago
A cell reference is also called a cell _______.
viva [34]
A cell reference is also called a cell address.
7 0
3 years ago
Anyone watch anime what's y'all race
slava [35]

Answer:

I do

Explanation:

I watch jojos bazaar adventure

4 0
3 years ago
Read 2 more answers
Other questions:
  • What is displayed in the alert dialog box after the following code is executed? var items = 3; for (var i = 1; i &lt;= items; i+
    8·1 answer
  • Li Chang has recently started his own business. He plans to launch his design for an application (app) for a smartphone. All of
    9·1 answer
  • The default ____ for a hyperlink is the folder location and the name of the file to which you will link.
    6·1 answer
  • File Sales.java contains a Java program that prompts for and reads in the sales for each of 5 salespeople in a company. It then
    8·1 answer
  • A Portable Document Format (PDF) can be opened with Adobe Acrobat Reader and many web browsers.
    14·1 answer
  • Complete main() to read dates from input, one date per line. Each date's format must be as follows: March 1, 1990. Any date not
    9·1 answer
  • The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible by four was declared to be a l
    7·1 answer
  • This career applies mathematical and theoretical knowledge in order to compare and produce computational solutions.
    14·2 answers
  • SHORT ANSWERS:
    7·1 answer
  • PLS HELP I GOT 30 MINS TO TURN THIS IN!!!
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!