Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 findTriples(vector numbers){

//WRITE YOUR CODE HERE

}

int main(){

//create test vector to pass to the function

vector 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(-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 triples = findTriples(testNumbers);

//display results

for(int i=0;i

cout<

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions