O(n) solution possibility (no need for a data structure)
void findpairs(int sum)
{
//given a set of numbers -50 to 50, find all pairs that add up to a certain sum that is passed in.
if (sum == 0)
{
cout 0)
{
for(int i = 0; i((sum/2)-1) && i>-26; i--)
{
if( (i - sum+i) == sum)
{
cout << i << " " << sum+i << "\n";
}
}
}
}
O(n^2) solution is just two double for loops.
O(n log n) solution will use a binary tree
O(n) solution will use a hash table