Priority Queue ArrayList HashMap
source link: https://www.codesd.com/item/priority-queue-arraylist-hashmap.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Priority Queue ArrayList HashMap
I have a HashMap whose key is distance and value is ArrayList which contains a list of vertices which are at a particular distance (i.e. key)
I want to make Priority Queue of HashMap(priority based on keys) to get all the vertices which are at a particular distance at a time.
is it possible to make such priority Queue (unbounded one) ? Could anyone help please ?
You can use class to encapsulate the distance and vertices. Implements the Comparable
interface or pass the Comparator
object when you'll new
the PriorityQueue
. you can do this following ...
class Node implements Comparable<Node> {
int distance;
List<Vertex> list;
public Node(int distance, List<Vertex> list) {
this.distance = distance;
this.list = list;
}
@Override
public int compareTo(Node o) {
// your compare logic goes here
return Integer.compare(this.distance, o.distance);
}
}
=====
public static void main(String[] args) {
PriorityQueue<Node> q = new PriorityQueue<>();
}
Related Articles
Implementing priority queue using hashmap
Compare for Priority Queue in JAVA
Priority queue with two Python priorities
Algorithm to create a & ldquo; Relative & rdquo; Priority queue? (C / C ++)
The easiest way to use the minimum priority queue with the key update in C ++
How do you use a binary heap to implement a priority queue?
Function for the priority queue in ocaml
Need a disk-based priority queue library, preferably for C
Overload Operator & lt; For the Priority Queue
STL Priority Queue - deleting an element
STL Priority Queue on Custom Class
C # Priority Queue
Priority queue with two priority values
Why does the Dijkstra algorithm need a priority queue when this regular queue version is also correct?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK