この記事では、JavaソートアルゴリズムのSleepSortソートについて説明します。次のように、参照のために共有してください。
非常に創造的なソートアルゴリズムを共有:SleepSort。スレッドの睡眠()を巧みに利用すると、コードは次のとおりです。
Public Class Sleepsort { / ** * @param args * / public static void main(string [] args){// todo auto-enerated method stub int [] ints = {1,4,7,3,8,9,9,2,6,5}; sortthread [] sortthreads = new sortthread [ints.length]; for(int i = 0; i <sortthreads.length; i ++){sortthreads [i] = new sortthread(ints [i]); } for(int i = 0; i <sortthreads.length; i ++){sortthreads [i] .start(); }}} class sortthread extends thread {int ms = 0; public sortthread(int ms){this.ms = ms; } public void run(){try {sleep(ms*10+10); } catch(arturnedexception e){e.printstacktrace(); } system.out.println(ms); }}この記事がみんなのJavaプログラミングに役立つことを願っています。