Funny ratio sleep Sorting Algorithm

Source: Internet
Author: User

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 );}}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.