I am playing around with list and I figure out how to merge two lists and all. But I have no idea how can I integrate one list onto another. For example A = {1,2,3,4,10,11} and B = { 5,6,7} Then my integrated list should be
{1,5,2,6,3,7,4,10,11}. I would have figured out of two lists are of the same length but they aren't. Two lists can be varied in terms of size.
I am writing a free function so here is my approach :
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <list>
usingnamespace std;
template <class T>
T integrateList(const& list<T> i, const& list<T> m)
{
list<T>::const_iterator iter;
what exactly do I need to do here?I know how I Can merge the two list?
But how can I integrate or collate them?
Also, if this is just an exercise to learn an STL container, consider using the std::set<> template instead,
which will give you both the uniqueness and the ordering of the elements you desire.
std::set<> is a container that does not allow you to insert duplicates, and by default when you walk
the container begin() to end() will return the contained values already sorted, lowest to highest (by default).