C++ STL priority queue of Node Pointers

I'm trying to implement a priority queue of Node*, where Node is a class I have defined myself. I realized that having a priority queue of pointers would mean that it would sort based on the address, rather than the value that the Node held, and so I searched through quite a few discussion forums to find a solution that would allow me to specify how to sort the Node objects in the priority queue; most agree that you need to write a struct that contains a function that takes as arguments 2 Node objects and returns the desired comparison. The f...Read more

priority queue - best data structure to record a Pareto front

May I ask if someone has already seen or faced the following problem?I need to handle a list of cost/profit values c1/p1, c2/p2, c3/p3,... that satisfies: c1≤c2≤c3≤c4... p1≤p2≤p3≤p4...This is an example: 2/3, 4/5, 9/15, 12/19 If one triesto insert 10/14 in above list, the operation is rejected because of the existingcost/profit pair 9/12: it is never useful to increase the cost (9->10)and decrease the profit (14->12). Such lists can arise for instance in (the states of) dynamic programming algorithms for knapsack problems, wherethe costs ...Read more

Heapsort vs Priority Queues

I just learned about Heapsort and Priority Queue and think they have about the same idea. Based on my understanding of Heapsort, it swap the item in room to the nth node and remove the largest item swapped with the nth node to the heap, then it sorts to maxheap. Where in priority sort I think maximum priority gets removed (just like in heapsort [I think]), then perhaps sort to maxheap again.Would this be right or how to distinguish the both?...Read more

How to achieve delayed queue with apache kafka?

How do I add delayed jobs on kafka? As I understand it doesn't deal with per message but per topic. My jobs have varying schedule in which I would like them to be consumed. Say one will be in the next 4 hours, another would be i Dec. 1, etc.Does kafka have native support for this or other 3rd party ways to achieve the same?I'm thinking of using Redis for the delayed queue instead, and push the job to kafka once its schedule has arrived but if possible I'd like to use only one dependency....Read more

Priority Queue sqaure root run time

I am having a Data Structures Exam and I am preparing from a list of review questions. The question I am stuck on is as follows:"Suppose your friend comes to you and claims that he has invented a super fast comparison based priority queue. The speed of the priority queue is as follows ( n is the number of items currently in the priority queue ): a. insert a new item in O(sqrt(logn)) time b. extract (remove and return) the smallest item from the queue in O(sqrt(logn)) time.Explain why your friend must be lying:"From what I understand t...Read more

Why Dijkstra's Algorithm uses heap (priority queue)?

I have tried using Djikstra's Algorithm on Cyclic weighted graph without using Priority queue (Heap) and it worked.Then I searched google that "why the hell do we need a priority queue to implement this??" As a result of the search I went through Wikipedia where I got to know that the original implementation does not uses Priority queue and runs in O(|V|2) i.e V square time .now if we just remove priority queue and use normal queue the running time is linear i.e. O(V+E). Please someone suggest then why do we need priority queue??...Read more

Priority queue in Erlang

I'm new to Erlang and I'm trying to port my Project Euler solutions in C# to Erlang. I have a priority queue implementation with unit tests. I'm wondering if I'm missing something(I probably do) if I was writing serious Erlang code.priority_queue.hrl-record(heap_node, { item :: any(), children :: [#heap_node{}] }).-type heap_node() :: #heap_node{}.-record(priority_queue, { root :: heap_node() | nil, comparer :: comparer() }).-type priority_queue() :: #priority_queue{}.-type comparer() :: fun((any(), any()) -> less | equal | greater).priority...Read more

how to shift this priority queue?

My program is supposed to do 4 operations: add, delete, show and exit using a priority queue... here is the code:#include<iostream>#include<conio.h>using namespace std;#define SIZE 5 /* Size of Queue */int f=0,r=-1; /* Global declarations */typedef struct PRQ{ int ele; int pr; int sign;}PriorityQ;PriorityQ PQ[SIZE];//***************************************************void PQinsert(int elem, int pre){ int i; /* Function for Insert operation */ if( r==SIZE-1) printf("\n\n Overflow!!!!...Read more