Question
Please help with this gomework question. Consider the problem of finding the pairs of integers in an input list that sum to 0. Assume that
Please help with this gomework question.
Consider the problem of finding the pairs of integers in an input list that sum to 0. Assume that the integers are distinct. This problem is easily solved in quadratic time by doing a brute-force implementation with two (nested) loops that examines all possible pairs.
Write a function that will take a vector of int values as argument and it will return the pairs of values in that vector that sum to 0. Write a brute-forced implementation as described above.
The main program has been written for you, you just have to write the code for the findPairs function.
#include
#include
#include
#include
using namespace std;
vector
}
int main(){
//create test vector to pass to the function
vector <int> testNumbers;
testNumbers.push_back(1);
testNumbers.push_back(54);
testNumbers.push_back(2);
testNumbers.push_back(-3);
testNumbers.push_back(-2);
testNumbers.push_back(58);
testNumbers.push_back(-54);
testNumbers.push_back(58);
testNumbers.push_back(68);
testNumbers.push_back(78);
testNumbers.push_back(-75);
testNumbers.push_back(-1);
//call the function
vector
//display results
for(int i=0;i
cout<
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started