Jump to content

Flatten a list: Difference between revisions

added C++
(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}}==
973

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.