天才算法之睡眠排序(C#实现)

最近看到这样一段代码觉得很有意思,记录一下:

using System;
using System.Threading;
// 睡眠排序
namespace SleepSort { class SleepSortMainEntence { static void Main (string[] args) { int[] a = new int[] { 123, 243, 32, 443, 72, 3 }; foreach (var item in a) { // 遍历数组 Thread th = new Thread (x => { Thread.Sleep (item * 10); //睡眠时间,时间越短,越不精确 System.Console.WriteLine (item); // 睡完输出 }); th.Start (); //开始线程 } } } }

原文出处:https://innei.ren/posts/programming/SleepSort-C

posted @ 2020-10-27 13:53  iTachiLEe  阅读(257)  评论(0编辑  收藏  举报