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
hona is buying a rug for her room. Store A has the rug for $45 with a 10% discount. Store B has the same rug for $46 and is offe
Fed [463]
Store b. This will have her paying 36.00 for the rug. Store A she will pay 40.50
7 0
3 years ago
Suppose you want to view a document that has several headings. what view would you use?
bija089 [108]
Um i think outline. :)
5 0
3 years ago
You are running your warehouse using Autonomous Data Warehouse (ADW) service and you noticed that a newly configured batch job i
Phantasy [73]

Answer:

<u>C. The new batch job is connected to the LOW consumer group.</u>

Explanation:

<em>Remember</em>, one of the main characteristics of the LOW consumer group <u>database service</u> is that queries would run serially.

Since in this case, we are told that the newly configured batch job is always running in serial, it most likely would be because the new batch job is connected to the LOW consumer group; as queries are designed to always run serially.

6 0
3 years ago
What term refers to mathematical equations used in Excel to perform calculations?
vovikov84 [41]

Formulas is the BEST answer to your question.

4 0
3 years ago
1. Name the first PC virus.<br> 2. In which language are viruses written for Microsoft programs?
Tju [1.3M]

Answer:

The first IBM PC virus in the "wild" was a boot sector virus dubbed (c)Brain, created in 1986 by Amjad Farooq Alvi and Basit Farooq Alvi in Lahore, Pakistan, reportedly to deter unauthorized copying of the software they had written. The first virus to specifically target Microsoft Windows, WinVir was discovered in April 1992, two years after the release of Windows 3.0.

Explanation:

HOPE THIS HELPS

6 0
3 years ago
Read 2 more answers
Other questions:
  • Wendy Patel is entering college and plans to take the necessary classes to obtain a degree in architecture. Research the program
    12·1 answer
  • Propose, two new, proudly South African ways, which you can visualize that the internet of things, can be used in at work to mak
    7·1 answer
  • What is data security
    14·1 answer
  • Which of these image sizes takes the most storage space?
    8·2 answers
  • When backing up a database, what is added to the file name?<br> On g metrix
    9·1 answer
  • CORRECT ANSWER GETS BRAINLIEST
    8·2 answers
  • What is data science?​
    15·1 answer
  • For her presentation on Italy, Matilda used a red background with light green text. When her friend critiqued her presentation,
    12·1 answer
  • Identify and explain 4 traditional (old ways) marketing approaches used by University uses in reaching
    7·1 answer
  • You defined a shoe data type and created an instance.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!