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
49
50
package edu.caltech.cs2.interfaces;
/**
* This interface represents a Priority Queue - a data structure that is very similar to a queue but
* stores values in ascending order.
* @param <E> Element type
*/
public interface IPriorityQueue<E> extends IQueue<IPriorityQueue.PQElement<E>> {
public static class PQElement<E> {
public final E data;
public final double priority;
public PQElement(E data, double priority) {
this.data = data;
this.priority = priority;
}
@Override
public int hashCode() {
return this.data.hashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof PQElement)) {
return false;
}
return this.data.equals(((PQElement)o).data);
}
@Override
public String toString() {
return "(" + this.data + ", " + this.priority + ")";
}
}
/**
* Increase the priority of the key at idx
* @param key - the new key with the new priority
*/
public void increaseKey(PQElement<E> key);
/**
* Decrease the priority of the key at idx
* @param key - the new key with the new priority
*/
public void decreaseKey(PQElement<E> key);
}