Skip to main content

Practice ยท 2 of 2

Stable even/odd reorder with std::list

Implement std::list<int> evens_first(std::list<int> l) that moves all even values before all odd values while preserving the relative order within each group. Use std::list::splice (O(1) node moves โ€” no element copies). Example: {1,2,3,4,5} becomes {2,4,1,3,5}.

Difficulty: intermediate

Back to lesson: Practice: Sequence container problems