Skip to main content

Practice · 2 of 2

Stable even/odd reorder with std::list

CHALLENGE
Difficulty: intermediate+25 XP

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}.

Back to lesson: Practice: Sequence container problems