PROGRAM :
Code:
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;
template <class S>
inline void PRINTELEMENTS (const S& cl, const char* optstr="")
{
typename S::constiterator ps;
std::cout << optstr;
for (ps=cl.begin(); ps!=cl.end(); ++ps)
{
std::cout << *ps << ' ';
}
std::cout << std::endl;
}
template <class S>
inline void INSERTELEMENTS (S& cl, int fst, int lst)
{
for (int j=fst; j<=lst; ++j)
{
cl.insert(cl.end(),j);
}
}
int main()
{
vector<int> cl1;
list<int> cl2;
INSERTELEMENTS(cl1,1,9);
copy (cl1.begin(), cl1.end(),
backinserter(cl2));
copy (cl2.begin(), cl2.end(),
ostreamiterator<int>(cout," "));
cout << endl;
}
OUTPUT :
Bookmarks