-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsleepsort.java
More file actions
48 lines (45 loc) · 735 Bytes
/
Copy pathsleepsort.java
File metadata and controls
48 lines (45 loc) · 735 Bytes
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
48
import java.util.Scanner;
class sort implements Runnable
{
private int a;
sort(int a)
{
this.a = a;
}
public void run()
{
try{
Thread.sleep(a);
System.out.print(a+" ");
}
catch(Exception e)
{}
}
}
public class sleepsort
{
public static void main(String args[])
{
sleepsort ss=new sleepsort();
Scanner ip=new Scanner(System.in);
System.out.println("Enter the number of elements");
int n=ip.nextInt();
int[] arr=new int[n];
System.out.println("Enter the elements");
for(int i=0;i<n;i++)
{
arr[i]=ip.nextInt();
}
System.out.println("Sorted array : ");
ss.ssmethod(arr);
}
public void ssmethod(int[] array)
{
for(int i:array)
{
sort s=new sort(i);
Thread t=new Thread(s);
t.start();
}
}
}