首页 > 编程语言 > 详细

睡排序--利用线程sleep的时间排序

时间:2018-06-12 20:46:38      阅读:244      评论:0      收藏:0      [点我收藏+]

/*
* 睡排序
* 利用线程休眠(苏醒时间)将数排序
*/
public class Demo {
public static void main(String[] args) {
int[] sortNum = {-1,0,1,4,7,3,8,9,2,6,5,555};
SortThread[] sortThreads = new SortThread[sortNum.length];
for (int i = 0; i < sortThreads.length; i++) { //接收数字充当休眠时间
sortThreads[i] = new SortThread(sortNum[i]);
}
for (int i = 0; i < sortThreads.length; i++) {
sortThreads[i].start();
}
}

}

 

 

 

class SortThread extends Thread{
int num = 0;
public SortThread(int num){
this.num = num;
}
public void run(){
try {
sleep(num);
} catch (InterruptedException e) {

e.printStackTrace();
}
System.out.println(num);
}
}

睡排序--利用线程sleep的时间排序

原文:https://www.cnblogs.com/zxwm/p/9174793.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!