ComparatorExample.
java
1 import [Link];
3
4 public class ComparatorExample {
5
6 public static void main(String[] args) {
7 PriorityQueue<State> pq = new PriorityQueue<>([Link]);
8
9 [Link](new State(5, 7, 9, 5));
10 [Link](new State(1, 2, 2, 2));
11 [Link](new State(4, 3, 9, 7));
12 [Link](new State(5, 9, 11, 1));
13 [Link](new State(1, 7, 5, 4));
14 [Link](new State(3, 5, 4, 5));
15
16 while (![Link]()) {
17 State e = [Link]();
18 [Link]([Link] + " " + [Link] + " " + [Link] + " " + [Link]);
19 }
20
21 }
22
23 }
24
25 class State {
26 public int from, to, cost, time;
27
28 State(int from, int to, int cost, int time) {
29 [Link] = from;
30 [Link] = to;
31 [Link] = cost;
32 [Link] = time;
33 }
34
35 public static Comparator<State> StateComparator = new Comparator<State>() {
36
37 @Override
38 public int compare(State st1, State st2) {
39 if ([Link] != [Link])
40 return [Link] - [Link];
41 return [Link] - [Link];
42 }
43
44 };
45 }
Page 1