Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,7 +1,7 @@
import std.stdio, std.array;
T[] strandSort(T)(/*in*/ T[] list) pure nothrow {
static T[] merge(T[] left, T[] right) pure nothrow {
T[] strandSort(T)(const(T)[] list) pure nothrow {
static T[] merge(const(T)[] left, const(T)[] right) pure nothrow {
T[] res;
while (!left.empty && !right.empty) {
if (left.front <= right.front) {
@ -19,8 +19,8 @@ T[] strandSort(T)(/*in*/ T[] list) pure nothrow {
while (!list.empty) {
auto sorted = list[0 .. 1];
list.popFront;
T[] leftover;
foreach (item; list)
typeof(sorted) leftover;
foreach (const item; list)
(sorted.back <= item ? sorted : leftover) ~= item;
result = merge(sorted, result);
list = leftover;
@ -30,6 +30,6 @@ T[] strandSort(T)(/*in*/ T[] list) pure nothrow {
}
void main() {
auto arr = [-2,0,-2,5,5,3,-1,-3,5,5,0,2,-4,4,2];
const arr = [-2, 0, -2, 5, 5, 3, -1, -3, 5, 5, 0, 2, -4, 4, 2];
arr.strandSort.writeln;
}