forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Sleep_Sort.java
47 lines (42 loc) · 973 Bytes
/
Sleep_Sort.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Created by jude on 21/10/16.
*/
public class sleepSort {
private static int[] elements = {3, 6, 3, 9, 10, 8, 2};
public static void main(String[] args)
{
sleepSortMethod(elements);
}
private static void sleepSortMethod(int[] elements) {
for(int element: elements)
{
Thread thread = new Thread(new sleepSortThread(element));
thread.start();
}
}
private static class sleepSortThread implements Runnable {
int element;
public sleepSortThread(int element) {
this.element = element;
}
@Override
public void run() {
try
{
Thread.sleep(element);
System.out.println(element);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
/* Output
2
3
3
6
8
9
10
*/