数据结构和算法——睡眠排序

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

参考视频:沙雕代码之【睡眠排序】深度讲解_哔哩哔哩_bilibili

你可能感兴趣的:(java,算法,数据结构)