Hi all,

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}. 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 :

#include <iostream>
#include <list>
using namespace 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?

}
int main()
{
  list<int> listA;
  list<int> listB;
  list<int> newList;

  listA.push_back(1);
  listA.push_back(2);
  listA.push_back(3);
  listA.push_back(4);
  listA.push_back(10);
  listA.push_back(11)

 
  listB.push_back(5);
  listB.push_back(6);
  listB.push_back(7);

  newList = integrateList(listA, listB);
  cout<<newList <<endl;
  return 0;
}

Thank you for any help.

Is merging the 2 lists into a 3rd list an option for you?

How can you merge two lists of different size? Is it even possible? I thought you can only merge two lists which are of the same size.
After merging two lists, the original lists will be empty..no? If so, that is not my options for sure!

Something like this : ?

1) Create a result list
2) Merge list A and list B
3) copy result list to list A, while making sure that list A has enough add at each insertion.

Something like this : ?

1) Create a result list

T inteGrateList(const list<T> i, const list<T> m)
{
    list<T>::const_iterator p;
   list<T> resultingList;
   i.merge(m) // merge list m in i; now m is empty


}

2) Merge list A and list B
3) copy result list to list A, while making sure that list A has enough add at each insertion.

This will basically merge the two lists but I wont get the output the way I desire. I think it will join the tail of one list with the head of another list!

>>But I have no idea how can I integrate one list onto another.

What requirements comes to mind when you think this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.