35 |
|
if (args.length > 0) |
36 |
|
n = Integer.parseInt(args[0]); |
37 |
|
|
38 |
< |
List<Integer> sorted = new ArrayList<Integer>(n); |
38 |
> |
List<Integer> sorted = new ArrayList<>(n); |
39 |
|
for (int i = 0; i < n; i++) |
40 |
|
sorted.add(new Integer(i)); |
41 |
< |
List<Integer> shuffled = new ArrayList<Integer>(sorted); |
41 |
> |
List<Integer> shuffled = new ArrayList<>(sorted); |
42 |
|
Collections.shuffle(shuffled); |
43 |
|
|
44 |
< |
Queue<Integer> pq = new PriorityQueue<Integer>(n, new MyComparator()); |
44 |
> |
Queue<Integer> pq = new PriorityQueue<>(n, new MyComparator()); |
45 |
|
for (Iterator<Integer> i = shuffled.iterator(); i.hasNext(); ) |
46 |
|
pq.add(i.next()); |
47 |
|
|
48 |
< |
List<Integer> recons = new ArrayList<Integer>(); |
48 |
> |
List<Integer> recons = new ArrayList<>(); |
49 |
|
while (!pq.isEmpty()) |
50 |
|
recons.add(pq.remove()); |
51 |
|
if (!recons.equals(sorted)) |
52 |
|
throw new RuntimeException("Sort test failed"); |
53 |
|
|
54 |
|
recons.clear(); |
55 |
< |
pq = new PriorityQueue<Integer>(shuffled); |
55 |
> |
pq = new PriorityQueue<>(shuffled); |
56 |
|
while (!pq.isEmpty()) |
57 |
|
recons.add(pq.remove()); |
58 |
|
if (!recons.equals(sorted)) |
59 |
|
throw new RuntimeException("Sort test failed"); |
60 |
|
|
61 |
|
// Remove all odd elements from queue |
62 |
< |
pq = new PriorityQueue<Integer>(shuffled); |
62 |
> |
pq = new PriorityQueue<>(shuffled); |
63 |
|
for (Iterator<Integer> i = pq.iterator(); i.hasNext(); ) |
64 |
|
if ((i.next().intValue() & 1) == 1) |
65 |
|
i.remove(); |