知识大全 睡眠排序
Posted 天才
篇首语:从来好事天生俭,自古瓜儿苦后甜。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 睡眠排序相关的知识,希望对你有一定的参考价值。
今天看到一个帖子 帖名叫《Genius sorting algorithm: Sleep sort》 看过之后感觉虽然实用价值不高 但挺受启发的 帖上来给大家分享下 Man am I a genius Check out this sorting algorithm I just invented 朋友 我真是个天才 快来看看我刚发明的排序算法 #!/bin/bash function f() sleep $ echo $ while [ n $ ] do f $ & shift done wait example usage: /sleepsort bash 再帖几个其他常用版本 以便擅长不同语言的朋友阅读 JAVA版 [java] public class SleepSort public static void main(String[] args) int[] ints = ; SortThread[] sortThreads = new SortThread[ints length]; for (int i = ; i < sortThreads length; i++) sortThreads[i] = new SortThread(ints[i]) for (int i = ; i < sortThreads length; i++) sortThreads[i] start() class SortThread extends Thread int ms = ; public SortThread(int ms) this ms = ms; public void run() try sleep(ms* + ) catch (InterruptedException e) // TODO Auto generated catch block e printStackTrace() System out println(ms)
cha138/Article/program/Java/hx/201311/25620相关参考