priority-queue

Java - PriorityQueue vs sorted LinkedList

Hello, Which implementation is less "heavy": PriorityQueue or a sorted LinkedList (using a Comparator)? I want to have all the items sorted. The insertion will be very frequent and ocasionally I will have to run all the list to make some operations. Thank you! ...

Java - Collections.binarySearch with PriorityQueue?

Hello, Can I use Collections.binarySearch() method to search elements in a PriorityQueue? Otherwise, how can I apply search algorithms to a PriorityQueue? I have this (class Evento implements Comparable): public class PriorityQueueCAP extends PriorityQueue<Evento>{ // (...) public void removeEventos(Evento evento){...

priority_queue with dynamic priorities

Hey, I have a server application which accepts incomming queries and executes them. If there are too many queries they should be queued and if some of the other queries got executed the queued queries should be executed as well. Since I want to pass queries with different priorities I think using a priority_queue would be the best choice...

priority queue with limited space: looking for a good algorithm

This is not a homework. I'm using a small "priority queue" (implemented as array at the moment) for storing last N items with smallest value. This is a bit slow - O(N) item insertion time. Current implementation keeps track of largest item in array and discards any items that wouldn't fit into array, but I still would like to reduce num...

Trying to write priority queue in Java but getting "Exception in thread "main" java.lang.ClassCastException"

For my data structure class, I am trying to write a program that simulates a car wash and I want to give fancy cars a higher priority than regular ones using a priority queue. The problem I am having has something to do with Java not being able to type cast "Object" as an "ArrayQueue" (a simple FIFO implementation). What am I doing wrong...

Efficiency of the STL priority_queue

I have an application (C++) that I think would be well served by an STL priority_queue. The documentation says: Priority_queue is a container adaptor, meaning that it is implemented on top of some underlying container type. By default that underlying type is vector, but a different type may be selected explicitly. and Priority...

JMS Priority set by a custom header

Hi, Is there a way to prioritize the messages in the JMS broker according to a custom header value? For Example: "purchase date". get oldest first etc. Please advise. ...

Java: PriorityQueue returning incorrect ordering from custom comparator??

I've written a custom comparator to compare my node classes, but the java priority queue is not returning my items in the correct order. Here is my comparator: public int compare(Node n1, Node n2){ if (n1.getF() > n2.getF()){ return +1; } else if (n1.getF() < n2.getF()){ return -1; } else { // equa...

STL Priority Queue - deleting an item

Hello, I want to implement a timer queuing system using the C++ STL priority_queue container adapter. My problem is that I want to occasionally cancel a timer, however there are no interfaces that enable me to easily delete an item in the priority_queue that is not the top item. Any suggestions?. Thank you for your help. ...

push in priorityqueue

I want to push some int to a priorityqueue but i can't! i used the queue.add() code but this code will return the sorted queue,please help,thank you! ...

Delayed_job custom failing assertions?

Hey all, I'm using delayed_job for a priority queue. I was wondering how do i define what a failed job is? Thanks. ...

Efficient priority list

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 priority queues which operate on heaps, but they don't seem to really suit my needs. They will reorganize the heap structure as soon as I will poll...

How do I use a priority queue in c++?

For example we have priority_queue<int> s; which contains some elements. What will be correct form of the following code: while (!s.empty()) { int t=s.pop();// this does not retrieve the value from the queue cout<<t<<endl; } ...

priority queue problem in python

I have a priority queue class that has only few functions like, if it is empty or not, push and pop an itme into it. But I need to check if a partuclar item is present in the queue or not? how would I do that?? ...

Creating a python priority Queue

Hello everyone, I would like to build a priority queue in python in which the queue contains different dictionaries with their priority numbers. So when a "get function" is called, the dictionary with the highest priority(lowest number) will be pulled out of the queue and when "add function" is called, the new dictionary will be added ...

F# priority queue

Does the F# library include a priority queue? Else can someone point to me an implementation of priority queue in F#? ...

Segmentation fault while using priority queues

I have a priority queue with elements of a class named A I need elements from this queue which may be lower down the queue (lesses priority). So , I am trying to pop a few elements until i get the element of my choice. Once i get the element of my choice i am planning to push all the elements i stored temporary in an array. I have a loo...

Co- and contravariant types in generic priority queue

I'm trying to implement in Scala a generic data type parameterized on a type T, which should be Ordered[T]. Specifically, it's a persistent version of Sleator & Tarjan's skew heap priority queues. After adding lots of complicated type parameter declarations based on the explanation here and in Odersky-Spoon-Venners, I'm down to one compi...

What's wrong with my Priority Queue's Pop method?

Based on Rob Pike's load balancer demo, I implemented my own priority queue, but my Pop method is not right, can anyone tell me what's wrong? package main import ( "fmt" "container/heap" ) type ClassRecord struct { name string grade int } type RecordHeap []*ClassRecord func (p RecordHeap) Len() int { return len(p) }...

C++ Vector/list of priority queues?

Why wouldn't C++ allow something like that ? I need to have multiple priority queues, the number of which would be determined at run time. This fails to compile std::vector<std::priorityqueue<Class A>>. Is there a better approach ? ...