|
// Runtime Generative Linear Recursion
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
bool makeVector(std::vector<int>& vec, int low, int high, int increment = 1)
{
if (low > high)
return false;
if (low == high)
return true;
else
{
vec.push_back(low); makeVector(vec, low+increment, high, increment);
}
return true;
}
int main()
{
std::vector<int> vec;
makeVector(vec, -5, 10, 2);
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, "\n"));
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.