previous | start | next

## Vector Parameters and Return Values (Return Values)

- A function can return a vector.
- Here is a function that collects all values that fall within a certain range.

  >     vector<double> between(vector<double> v,
  >        double low, double high)
  >     {
  >        vector<double> result;
  >        for (int i = 0; i < v.size(); i++)
  >           if (low <= v[i] && v[i] <= high)
  >              result.push_back(v[i]);
  >        return result;
  >     }

- Here is a function that collects the positions of all matching values in a vector of integers.

  >     vector<int> find_all_between(vector<double> v,
  >        double low, double high)
  >     {
  >        vector<int> pos;
  >        for (int i = 0; i < v.size(); i++)
  >        {
  >           if (low <= v[i] && v[i] <= high)
  >              pos.push_back(i);
  >        }
  >        return pos;
  >     }

previous | start | next