Re: Sorting a subrange

2018-11-16 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 16 November 2018 at 12:08:33 UTC, Stanislav Blinov wrote: import std.range.primitives : isRandomAccessRange; auto sortSubRange(R)(R range, size_t i, size_t j) if (isRandomAccessRange!R) { import std.algorithm.sorting : topN, partialSort; size_t start = i; if (i != 0) {

Re: Sorting a subrange

2018-11-16 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 16 November 2018 at 11:24:20 UTC, Per Nordlöw wrote: /** Sort sub-range [sub_begin, sub_end] of [begin, end]. * * Describe at https://www.youtube.com/watch?v=0WlJEz2wb8Y&t=2686s */ template// I models RandomAccessIterator void sort_subrange(I begin, I end,

Sorting a subrange

2018-11-16 Thread Per Nordlöw via Digitalmars-d-learn
How do I sort a subrange of a range `x` where the subrange is defined by a lower and upper (in this case exlusive) element contained within `x`? auto x = [1,2,7,4,2,6,8,3,9,3]; auto y = sortSubRange(x, 3,5]; should yield `y` being [3,3,4] and `x` being [a ,3,3,4, b] where