Question: please help with this homework question. Consider the problem of finding the triples of integers in an input list that sum to 0. Assume that
please help with this homework question.
Consider the problem of finding the triples of integers in an input list that sum to 0. Assume that the integers are distinct. This problem is easily solved in cubic time by doing a brute-force implementation with three (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 triples 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 findTriples function.
#include
#include
#include
#include
using namespace std;
vector
//WRITE YOUR CODE HERE
}
int main(){
//create test vector to pass to the function
vector
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(-52);
testNumbers.push_back(58);
testNumbers.push_back(68);
testNumbers.push_back(78);
testNumbers.push_back(-75);
testNumbers.push_back(88);
//call the function
vector
//display results
for(int i=0;i cout< }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
