Topic: STL join two lists
Author: James Junmin Fan <jfan@cs.utexas.edu>
Date: 2000/03/14 Raw View
This should be quite simple, but I just couldn't find it out.
Given two STL lists/slists, I want to join them into one with O(1) complexity. A
ny ideas, TIA?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Dietmar Kuehl <dietmar.kuehl@claas-solutions.de>
Date: 2000/03/14 Raw View
Hi,
In article <8agfat$o6k$1@news.cs.utexas.edu>,
James Junmin Fan <jfan@cs.utexas.edu> wrote:
> Given two STL lists/slists, I want to join them into one with O(1)
> complexity. Any ideas, TIA?
This can be done with 'std::list<T>::splice()':
template <typename T>
void join(std::list<T>& l1, std::list<T>& l2) {
l1.splice(l1.end(), l2);
}
Of course, this operation is destructive in the sense that after this,
'l2' is empty.
--
<mailto:dietmar.kuehl@claas-solutions.de>
homepage: <http://www.informatik.uni-konstanz.de/~kuehl>
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]