视频讲解地址:【手把手带你写十大排序】11.总结&&睡眠排序(Java语言)_哔哩哔哩_bilibili
睡眠排序效率很低,切勿当真!
代码:
public class SleepSort {
public void sortFunction(int[] array) {
for (int i = 0; i < array.length; i++) {
final int num = array[i];
new Thread(() -> {
try {
Thread.sleep(num);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.print(num + " ");
}).start();
}
}
}