public class SleepSort {
public static void main(String[] args) {
int[] nums = new int[]{1, 2, 34, 4, 45, 56};
sleepSort(nums);
}
public static void sleepSort(int[] nums) {
for (int i = 0; i < nums.length; i++) {
final int num = nums[i];
new Thread(() -> {
try {
Thread.sleep(num);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(num);
}).start();
}
}
}
数据结构和算法——睡眠排序
最新推荐文章于 2024-05-11 10:24:57 发布