搞笑的排序演算法—睡覺排序
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
/**
* CopyRight (c) 2018 freebug.org Technology Inc.
*
* @author jimmiesong@yeah.net
* @date 2018/11/20 11:17
* @since 1.8
*/
public class SleepSort {
public static void main(String[] args) {
CountDownLatch latch = new CountDownLatch(array.length);
int[] array = new int[]{5446, 584, 1, 4, 3, 777, 8, 9, 33, 6666, 33};
for (int i = 0; i < array.length; i++) {
final int value = array[i];
new Thread(() -> {
latch.countDown();
try {
Thread.sleep(value);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print(value + "
");
}).start();
}
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}