priority-queue

Is Heap considered an Abstract Data Type?

折月煮酒 提交于 2020-01-02 01:45:07
问题 I'm taking Data-Structure course and got a little confused about what is considered to be an ADT (Abstract Data Type) and what isn't (and if it isn't an ADT then it must be the implementation?). Specifically, I'm talking about Heap. I've read in Wikipedia that " heap is a specialized tree-based data structure" does that mean it is an ADT? if so, then I can't understand the following line, also from Wikipedia "The heap is one maximally efficient implementation of an abstract data type called a

What is a Calendar Queue?

霸气de小男生 提交于 2019-12-31 21:36:11
问题 I am working on a building a discrete event simulator. Wikipedia mentioned that there are several general purpose priority queues that are good for use in DES's. Specifically, it mentions that a Calendar Queue is a good structure. I found one pdf (from 1988) that mentions Calendar Queues, but for the most part I can't find anything else out about them. Would someone mind explaining what Calendar Queue's are, how they're used, and where I might find a sample implementation? 回答1: A Google

What is a Calendar Queue?

北城余情 提交于 2019-12-31 21:35:49
问题 I am working on a building a discrete event simulator. Wikipedia mentioned that there are several general purpose priority queues that are good for use in DES's. Specifically, it mentions that a Calendar Queue is a good structure. I found one pdf (from 1988) that mentions Calendar Queues, but for the most part I can't find anything else out about them. Would someone mind explaining what Calendar Queue's are, how they're used, and where I might find a sample implementation? 回答1: A Google

Priority Queue Comparison

大城市里の小女人 提交于 2019-12-31 19:19:08
问题 I'm trying to declare a priority queue in c++ using a custom comparison function... So , I declare the queue as follows: std::priority_queue<int,std::vector<int>, compare> pq; and here's the compare function : bool compare(int a, int b) { return (a<b); } I'm pretty sure I did this before, without a class,in a similar way, but now, this code doesn't compile and I get several errors like this : type/value mismatch at argument 3 in template parameter list for 'template<class _Tp, class _Sequence

Print content of priority queue[java]

这一生的挚爱 提交于 2019-12-31 00:18:07
问题 How do I make the print_queue work properly in java? This is my own implementation of queue. Using Iterator() works fine, except it prints numbers in random order. package data_structures_java ; import java.util.Iterator; import java.util.PriorityQueue ; import java.util.* ; public class Queue_implementation { PriorityQueue<Integer> actual_queue ; public Queue_implementation(){ actual_queue = new PriorityQueue<Integer>() ; } public void add(int num){ actual_queue.add(num) ; } public int

How to get inverse of a comparator in java

老子叫甜甜 提交于 2019-12-30 17:31:29
问题 In a method I receive a generic object E extends Comparable<E> as an argument. Now i want to create two priority queues.One which uses the comparator used by E and other queue which uses the opposite of comparator used by E(i.e. if E uses '<' then second queue must use '>='). Please hep me how to create two such queues. queue2=new PriorityQueue<E>(0,Collections.reverseOrder(e)); I am getting the error that reverseOrder is not applicable. please help 回答1: Look at Collections.reverseOrder. 回答2:

Scala: Is there a way to use PriorityQueue like I would in Java?

跟風遠走 提交于 2019-12-30 09:49:27
问题 I have a class that I would like to use in a scala.collection.mutable.PriorityQueue, but I don't want to make it Ordered[A] just for this one purpose. I don't consider the ordering I want to use with respect to the PriorityQueue as the natural ordering of the class. class MyObject (sequence: Int, values: List[String]) ... So, in my PriorityQueue, I would like the values to be ordered by 'sequence'. However, just because two objects have the same sequence doesn't make them naturally equal

In a FIFO Qeueing system, what's the best way the to implement priority messaging

那年仲夏 提交于 2019-12-30 02:15:48
问题 For message-oriented middleware that does not consistently support priority messages (such as AMQP) what is the best way to implement priority consumption when queues have only FIFO semantics? The general use case would be a system in which consumers receive messages of a higher priority before messages of a lower priority when a large backlog of messages exists in Queue(s). 回答1: Given only FIFO support for a given single queue, you will of course have to introduce either multiple queues, an

Java: PriorityQueue returning incorrect ordering from custom comparator? [duplicate]

偶尔善良 提交于 2019-12-29 07:49:08
问题 This question already has answers here : The built-in iterator for java's PriorityQueue does not traverse the data structure in any particular order. Why? (5 answers) Closed 3 years ago . 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 { // equal return 0

The order of the PriorityQueue is wrong

南笙酒味 提交于 2019-12-29 01:45:10
问题 I meet a problem about order of PriorityQueue in Java 8, Intellij Idea, when I add the third number in the queue, the order is wrong, but only the third one have this problem, here is my code. import java.util.*; public class vector { static Queue<Integer> q=new PriorityQueue<Integer>(); public static void addNum(int num) { q.add(num); } public static void main(String args[]) { addNum(-1); addNum(-2); addNum(-3); addNum(-4); addNum(-5); } } I try to debug the code, after addNum(-3), the queue