C++ Linked list behavior

為{幸葍}努か 提交于 2019-12-05 10:32:18

You need to copy the elements. Consider something like this:

std::copy(a.begin(), a.end(), std::inserter(b, b_iterator));

If you want the same nodes shared by two lists, this is simply not supported by std::list (STL containers always have exclusive ownership). You can avoid duplicating the elements by storing pointers in the list, or by using boost::ptr_list, which internally stores pointers but offers a nicer API.

Try insert:

B.insert( position, A.begin(), A.end() );

to insert copies of the elements of A in B before 'position'. A itself remains unchanged. See this link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!