came back with other question about vector array function I am writing. I need some hints on how to return the number next to the interesting number I am looking for??
cull's job is to call your interesting function to create and return an array
that consists of all the interesting elements of v together will all the
elements of v that are next to interesting numbers.
For example, if your interesting function returns true for numbers that are
multiples of 10, and v held {9, 5, 10, 20, 8, 47, 63, 1, 70},
then cull would return a vector that held {5, 10, 20, 8, 1, 70}
Your cull function should work properly for any interesting function,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
bool interesting(unsigned n)
{
return (n % 10 == 0);
}
vector<unsigned> cull(const vector<unsigned> & v)
{
vector<unsigned> x;
unsigned temp;
for (unsigned i = 0; i < v.size(); i++)
{
if (interesting(v[i]))
x.push_back(v[i]);
}
return x;
}
|
obviously this only output 10,20,70
do I need to use two loops or some other variables ??