-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHPQSort.java
45 lines (34 loc) · 942 Bytes
/
HPQSort.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
package projectCode20280;
import java.util.LinkedList;
import java.util.Random;
import java.util.stream.Collectors;
/*
Implementation of the HPQSort, with timing in nanoseconds.
*/
public class HPQSort
{
public static void main(String[] args)
{
int n = 100;
while (n < 1000)
{
LinkedList<Integer> sll = new Random().ints(0, 1000).distinct().limit(n).boxed().collect(Collectors.toCollection(LinkedList::new));
HeapPriorityQueue<Integer, Integer> hpq = new HeapPriorityQueue<Integer, Integer>();
long startTime = System.nanoTime();
while (!sll.isEmpty())
{
int e = sll.removeFirst();
hpq.insert(e, e);
}
while(!hpq.isEmpty())
{
int e = hpq.removeMin().getKey();
sll.addLast(e);
}
long endTime = System.nanoTime();
long elapsedTime = endTime - startTime;
System.out.println(n + ", " + elapsedTime);
n = (int) (n * 1.01);
}
}
}