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

java 复制代码
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

相关推荐
陈大爷(有低保)几秒前
题目:基于TCP/IP用DOM4j修改XML
java·服务器·tcp/ip
m0_7387559213 分钟前
.ideavimrc在idea打不开
java·vim·intellij-idea
超级小的大杯柠檬水13 分钟前
IDEA中实现springboot热部署
java·spring boot·intellij-idea
Ace'14 分钟前
蓝桥杯15届C/C++B组省赛题目
数据结构·算法·蓝桥杯
1 ‍♂️‍️14 分钟前
链表(3)链表的基本操作
数据结构·链表
攀小黑17 分钟前
IDEA 24.1 could not autowire. No beans of ‘***‘ type found. 取消 某个类型的 警告
java·ide·intellij-idea
腊笔不小新xingo26 分钟前
READONLY You can‘t write against a read only replica
java·redis·bootstrap
JavaGuide35 分钟前
一条 SQL 语句在 MySQL 中是如何执行的?
java·数据库·后端·mysql
andyleung52042 分钟前
murmur 算法
算法
阿华的代码王国43 分钟前
【JavaEE】——多线程(join阻塞,计算,引用,状态)
java·开发语言·数据结构·java-ee