线程休眠排序

    //线程休眠排序(沙雕排序,仅图一乐呵),时间复杂度全取决于数组中元素的大小!,而且会存在很多bug!!
    private static void threadSort(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();
        }
    }

如果待排序数组中有很大的元素,如int型中最大为21亿,给个21亿元素,线程就要休眠几十个小时!!!

而且如果元素过多,末尾存在极小值,可能会出现排序错误!!

posted @ 2022-04-09 09:44  Saryon  阅读(83)  评论(0)    收藏  举报