Open
Description
Sort can be implemented via scan by performing an inserting incoming elements into a vector.
To find the right position to insert can be found using a binary search.
This approach would lead to a runtime complexity of O(n log n).
potential API:
range()
>> scan( vector<int>{}, sort() )
>> drop(4)
>> take(1);
// should return {4,3,2,1,0}
To limit the size of the buffer, a higher order function may be handy eg.:
range()
>> scan( vector<int>{}, sort() | slice(10) );
Activity