Sorting algorithms/Strand sort: Difference between revisions
Content added Content deleted
(Small improvements in second D entry) |
(→Faster version using slices: we're already using the identifier "result" in the enclosing function, better not use it also in the nested function, "res" is clear enough) |
||
Line 285: | Line 285: | ||
T[] strandSort(T)(/*in*/ T[] list) pure nothrow { |
T[] strandSort(T)(/*in*/ T[] list) pure nothrow { |
||
static T[] merge(T[] left, T[] right) pure nothrow { |
static T[] merge(T[] left, T[] right) pure nothrow { |
||
T[] |
T[] res; |
||
while (!left.empty && !right.empty) { |
while (!left.empty && !right.empty) { |
||
if (left.front <= right.front) { |
if (left.front <= right.front) { |
||
res ~= left.front; |
|||
left.popFront; |
left.popFront; |
||
} else { |
} else { |
||
res ~= right.front; |
|||
right.popFront; |
right.popFront; |
||
} |
} |
||
} |
} |
||
return |
return res ~ left ~ right; |
||
} |
} |
||