前言
在网上看到了这个算法,觉得很是厉害。
能想出这种算法的多半是个人才,所以记录下,也算是分享。
写程序,要拓宽思路。
代码
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 
 | import java.util.Scanner;
 public class SleepSort implements Runnable {
 private final int num;
 
 public SleepSort(int num) {
 this.num = num;
 }
 
 public static void main(String[] args) {
 Scanner scanner = new Scanner(System.in);
 int[] nums = new int[10];
 for (int i = 0; i < 10; i++) {
 nums[i] = scanner.nextInt();
 }
 
 for (int j : nums) {
 new Thread(new SleepSort(j)).start();
 }
 }
 
 @Override
 public void run() {
 try {
 Thread.sleep(num * 100);
 System.out.println(num);
 } catch (InterruptedException e) {
 e.printStackTrace();
 }
 }
 }
 
 | 
后记
叹为观止的算法! 时间复杂度为O(max(input))