priority-queue Questions
3
I need a min-heap in Matlab and I'm trying to use Java's PriorityQueue. I'm stuck on how to supply the Comparator.
So far I have initialized the PriorityQueue and can add one value-index pair to it...
Drowsy asked 28/3, 2011 at 3:30
20
Solved
I have priority queue in Java of Integers:
PriorityQueue<Integer> pq= new PriorityQueue<Integer>();
When I call pq.poll() I get the minimum element.
Question: how to change the cod...
Parallax asked 12/6, 2012 at 19:5
5
Solved
How can we use STL priority_queue for struct ?
Any illustration of pushing & popping , where struct has multiple data-types?
Say : struct thing { int a; char b;} glass[10]; .Now how can i put ...
Insinuating asked 24/3, 2013 at 17:56
1
Solved
I am experiencing something that is confusing me.
While working through problems in javascript on leetcode, I came across a solution that implemented a MaxPriorityQueue in the solution.
The posted ...
Demmy asked 28/6, 2022 at 18:17
4
Solved
What is the complexity of the addAll method of PriorityQueue. Does it add one element at a time resulting in O(n log n) or does it use a build heap process that creates a heap out of unordered elem...
Astroid asked 14/1, 2013 at 1:10
7
Solved
I want to get the next item in queue but I don't want to dequeue it. Is it possible in Python's queue.PriorityQueue? From the docs, I don't see how can it be done
Forequarter asked 15/2, 2012 at 4:34
2
Solved
How can I configure std::priority_queue to ignore duplicates?
When I add a key that is already contained then this new one should be ignored. (In my case, the priority for the old and the new one ...
Rhoea asked 10/5, 2011 at 18:7
3
Solved
I am trying to utilize a PriorityQueue from the queue class. However, i'm having issues putting custom objects into my PQ. I have implemented the __cmp__ function below:
def __cmp__(self, other):
...
Marcelo asked 18/4, 2017 at 20:0
2
I am using
from queue import PriorityQueue
pq = PriorityQueue()
pq.put((3, "Harry"))
pq.put((4, "Harry"))
pq.put((2, "Mary"))
This now creates two entries of "Harry". Am I supposed to remove al...
Methylnaphthalene asked 26/4, 2020 at 1:27
2
Solved
For example, given a List of Integer List<Integer> list = Arrays.asList(5,4,5,2,2), how can I get a maxHeap from this List in O(n) time complexity?
The naive method:
PriorityQueue<Integer&...
Latinity asked 27/8, 2021 at 23:48
3
Solved
When using a min/max-heap algorithm, priorities may change. One way to handle this is to removal and insert the element to update the queue order.
For priority queues implemented using arrays, thi...
Ronaronal asked 29/10, 2017 at 1:31
5
Solved
I am maintaining a set of unique_ptr instances in a priority_queue. At some point, I want to get the first element and remove it from the queue. However, this always produces a compiler error. See ...
Electrotype asked 21/5, 2013 at 2:2
4
Solved
I am trying to copy items out of a priority queue and into an ArrayList. for some reason, when there are three or four items, it stops after adding two items to the list.
If there are 5 items, it ...
Orcutt asked 19/4, 2018 at 22:32
6
Solved
It seems that a priority queue is just a heap with normal queue operations like insert, delete, top, etc. Is this the correct way to interpret a priority queue? I know you can build priority queues...
Ophiuchus asked 24/9, 2013 at 22:34
8
Solved
I'm trying to use a PriorityQueue to order objects using a Comparator.
This can be achieved easily, but the objects class variables (with which the comparator calculates priority) may change after...
Boxcar asked 9/12, 2009 at 2:28
2
Solved
I was trying to implement a sample program using heap, and I am able to Push and Pop from the Heap. I was able to implement the Push and Pop methods and use them as follows:
import "container/...
Banditry asked 9/8, 2020 at 16:39
4
Iam trying to build a priority queue using PriorityQueue in Python, but instead of element to be considered for priority comparison, I want it to use the return value from a function after passing ...
Abuttal asked 12/9, 2019 at 1:15
3
Solved
I know the std::priority_queue class implements a minheap. Is there a way to use this as a Max heap? Or is there an alternative Maxheap structure? I know I can use the std::make_heap() function on ...
Withershins asked 30/7, 2019 at 12:6
10
Solved
for (Event e : pq)
doesn't iterate in the priority order.
while(!pq.isEmpty()){
Event e = pq.poll();
}
This works but empties the queue.
Thorr asked 14/11, 2011 at 22:29
4
Solved
I'm searching for a kind of priority queue which allows me to give two priorites.
I want that it just check for the first value then for the second one
Here is some Code
import Queue
class Job(...
Cinerarium asked 29/3, 2014 at 15:59
4
I would like to implement a priority queue which would inject my objects - Nodes to the queue with respect to one field - f. I have already written List with custom comparer but this would require ...
Mcauliffe asked 20/12, 2012 at 22:13
7
I'm trying to implement Dijkstra's algorithm for finding shortest paths using a priority queue. In each step of the algorithm, I remove the vertex with the shortest distance from the priority queue...
Saturnalia asked 5/8, 2011 at 7:5
2
I'm using the heapq module to determine the smallest item in a list.
I have this below code, but the heapq.heapify() return value is None.
How do I get the result in a new list?
>>> a=h...
Attestation asked 11/9, 2012 at 16:8
5
Solved
I am looking for an efficient data structure to represent a priority list. Specifically I need to assign a priority to a set of items and return only the top scoring items. I have looked into prior...
Anaclinal asked 14/7, 2010 at 11:47
3
Solved
How a Priority Queue a Queue Data Structure. Since it doesn't follow FIFO, shouldn't it be named Priority Array or Priority Linked LIst majorly because Priority Queues don't follow a fashion like a...
Vo asked 28/11, 2016 at 6:50
© 2022 - 2024 — McMap. All rights reserved.