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]
3 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]3 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
True or False? A supervisory control and data acquisition (SCADA) device is a computer that controls motors, valves, and other d
Gekata [30.6K]

Answer:

The correct answer to the following question will be "True".

Explanation:

SCADA is a hardware and software elements program that permits industrial enterprises to:

  • Agricultural processes are regulated locally or globally.
  • The human-machine interaction program specifically interfaces with equipment such as cameras, switches, generators, motors and much more.
  • Track, store, and process the data in real-time.

Therefore, the given statement is true.

4 0
3 years ago
Analog footage can be digitized using video _____ equipment.â
Zepler [3.9K]

Analog footage can be digitized using video capture equipment. <span>
<span>Someone can shoot a footage with an analog camera which will be stored on a tape, and if you need to convert it into a digital format you will need a computer's video capture to save that as a digital output source.</span></span>

7 0
3 years ago
Which is a feature of a strong thesis statement? A) It presents only the facts. B) It is open-ended. C) It answers the central q
olchik [2.2K]
C. It answers the central question
3 0
4 years ago
Two friends can share 100 songs from their Bluetooth enabled mobile devices
Umnica [9.8K]

Answer:

A

Explanation:

If they are connected via bluetooth, you can share unlimited amounts of anything.

6 0
3 years ago
1.What is aperture priority mode? When might you use this mode on a camera?
miss Akunina [59]

The answers are too long. I have compiled them in Word and attached them below.

Download docx
8 0
3 years ago
Other questions:
  • How many water bottles must be collected to win?
    8·2 answers
  • What is the unit of measure that specifies the value of cellspacing?
    9·1 answer
  • Hidden-surface removal is the process of:
    14·1 answer
  • Create the following matrix M: 1 7 13 19 25 ?-3 9 15 21 27 5 11 17 2329By writing one command and using the colon to address ran
    8·1 answer
  • If an Administrator performs a clean install of Windows Server 2012 R2 on a new server, and then moves critical domain services
    9·1 answer
  • Which of these statements most accurately describes cookies?They have the capability to execute malicious software.Each cookie f
    12·1 answer
  • Sometimes your Internet is slow and sluggish, what are some common problems that affect network functionality. Check all that ap
    14·1 answer
  • The point of entry from a wireless device to a wired network is performed at a device called a(n) ____________________.
    10·1 answer
  • Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 5 as long as the
    10·1 answer
  • Identify the places in the code where there are object-oriented concept violations, content coupling, common coupling, control c
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!