Write a function that will take a vector of int values

Assignment Help Computer Engineering
Reference no: EM132096033

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 <vector>

#include <iostream>

#include <sstream>

#include <chrono>

using namespace std;

vector <string> 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 <string> pairs = findPairs(testNumbers);

//display results

for(int i=0;i<pairs.size(); ++i)

cout<<pairs[i]<<endl;

}

Reference no: EM132096033

Questions Cloud

Linear relation among air temperature : How do I determine if there is a linear relation among air temperature x1?, wind speed x2?, and wind chill y from the data shown below
Determine the? p-value of hypothesis test : The data below represents the population of a certain country every 10 years for the years? 1900-2000. How do I determine the? least-squares regression?
Develop a web-based pothole tracking and repair system : Why is it that many software developers don't pay enough attention to requirements engineering? Are there ever circumstances where you can skip it?
Develop a method with java program : Develop a method with java program. Write a main method to test your method.
Write a function that will take a vector of int values : 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.
Interval about slope of true? least-squares regression : How would I construct a? 95% confidence interval about the slope of the true? least-squares regression line shoeing the Lower and Upper Bound?
Evidence of a problem in the area : Was it evidence of a problem in the area, or was it a chance? Can you verify this? Would Binomial or Poisson distribution be suitable for modeling this case?
Identify the rows who destination network has any chance : Identify the rows who destination network has any chance of matching the IP address (compare the first three octets)
Can you explain confidence interval to me : Can you explain confidence interval to me? For example: when someone is asking what is the 95% CI for age range in a sample.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd