Flatten a list: Difference between revisions

Content deleted Content added
Ce (talk | contribs)
added C++
Line 6:
 
C.f. [[Tree traversal]]
 
=={{header|C++}}==
<lang cpp>
#include <list>
#include <boost/any.hpp>
 
typedef std::list<boost::any> anylist;
 
void flatten(std::list<boost::any>& list)
{
typedef anylist::iterator iterator;
 
iterator current = list.begin();
while (current != list.end())
{
if (current->type() == typeid(anylist))
{
iterator next = current;
++next;
list.splice(next, boost::any_cast<anylist&>(*current));
next = current;
++next;
list.erase(current);
current = next;
}
else
++current;
}
}
</lang>
 
=={{header|Common Lisp}}==