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[] result;
T[] res;
while (!left.empty && !right.empty) {
while (!left.empty && !right.empty) {
if (left.front <= right.front) {
if (left.front <= right.front) {
result ~= left.front;
res ~= left.front;
left.popFront;
left.popFront;
} else {
} else {
result ~= right.front;
res ~= right.front;
right.popFront;
right.popFront;
}
}
}
}
return result ~ left ~ right;
return res ~ left ~ right;
}
}