Funny ratio sleep Sorting Algorithm
Sleep sorting means that the sorting elements are used as the sleep time of the thread, and will be output after sleep ~
The larger the element, the later the waking up, the later the output, and then the sorting is not completed?
Package com. lean; the larger the value of the element in the public class SleepSort {/** array, the longer the sleep time. When sleep is short, * sort is output first. The actual meaning of sorting is not great and the time is too long. Happy! */public static void main (String [] args) {int a [] = {5, 6, 7, 1, 3, 2, 4, 9, 8 }; // create a sleep thread SortThread t [] = new SortThread [. length]; // initialize the sleep thread for (int I = 0; I <t. length; I ++) {t [I] = new SortThread (a [I]); t [I]. start () ;}}// sortThread is a dynamic class. When used as an internal class, add static. Otherwise, it will be placed as an external class ~~ Ha class SortThread extends Thread {int MS; public SortThread (int MS) {this. ms = ms;} @ Overridepublic void run () {super. run (); try {sleep (ms * 10 + 10);} catch (InterruptedException e) {// TODO Auto-generated catch blocke. printStackTrace ();} System. out. println (MS );}}