Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

}

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 pairs = findPairs(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

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

More Books

Students also viewed these Databases questions

Question

Write the number in the form a + bi. e 2+i

Answered: 1 week ago