Sleep Sort の C#/.NET4 版

※ 参考: Sleep sortの各言語での実装まとめ

// Sleep Sort C#/.NET4 版
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
public static class SleepSort
{
public static IEnumerable<T> Sort<T>(this IEnumerable<T> collection, Func<T, int> convert)
{
var queue = new ConcurrentQueue<T>();
collection.AsParallel().ForAll(
value => {
Thread.Sleep(convert(value));
queue.Enqueue(value);
}
);
return queue;
}
}
static class Program
{
static void Main()
{
var sortedCollection = new[] { 30, 200, 70, 400, 800, 35 }.Sort(x => x);
foreach (var item in sortedCollection)
Console.WriteLine(item);
}
}

.NET

Posted by Fujiwo