What I have in mind is a SortedIterator
, which accepts a Less
function that would be used to sort the container with all the known algorithms.
The brute force implementation would of course either keep a copy of the original elements, or keep references/pointers to the elements in the original list.
Is there an efficient way to iterate in a well-defined order without actually sorting the list? I'm asking this out of algorithmic curiosity, and I expect the answer to be no (or yes with a big but). It is asked out of a C++ style mindset, but is in fact a quite general language-agnostic premise.