Questions tagged [priority-queue]

A priority queue is a regular queue or stack data structure, but where additionally each element has a "priority" associated with it.

0
votes
0answers
12 views

Priority Queue with ArrayList Parameters

I am trying to implement a Priority Queue of two ArrayLists in Java. I want each in the queue to return (String, Integer) and I have an ArrayList of Strings and a separate ArrayList of Integers.I ...
0
votes
1answer
75 views

Deleting from Indexed Priority Queue (java)

I have an Indexed Minimum Priority Queue implemented as a heap. When deleting an indexed element, the code is:public void delete(int i) {if (i < 0 || i >=maxN) throw new ...
0
votes
1answer
27 views

Implementing Priority Queue

I am attempting to implement insertion, find minimum, and delete minimum functions for a primary queue. I also have tests to ensure that my code is working properly by checking it alongside another ...
0
votes
0answers
22 views

run a runnable jobs at a particular time in multithreaded way

I am working on below interview question:A server receives requests from different clients. Each client send aRunnable job and time on which this job should be run. Write a javaprogram that ...
-2
votes
1answer
40 views

HeapSort returns wrong array (Java)

My HeapSort returns an array that is not in the correct order.My original array is {15, 9, 11, 5, 6, 7}, and when run the heapSort method, I am getting this array: {15, 11, 9, 6, 7, 5}.I printed ...
0
votes
1answer
28 views

Priority Linked Queue add method assistance

I'm trying to implement priority queue using linked nodes, and I have all of my methods working correctly except for the add method. The purpose of the add method is to add a comparable object into ...
1
vote
2answers
29 views

Java PriorityQueue with comparator implementation is not returning reverse order of the string [duplicate]

PriorityQueue<String> q2=new PriorityQueue<String> (15, new Comparator<String>() {@Overridepublic int compare(String o1, String o2) {//System.out....
1
vote
2answers
26 views

Creating a priority queue using a heap in Python

I am new to Python so excuse for the silly mistakes...I am trying to create a priority queue using heap in python(2.7.15) and my code doesn't obviously work.pq=[] # list ...
1
vote
0answers
30 views

C programming using data structures (Priority Queue) storing and displaying a character and integer together int the queue

#include <stdio.h>#include <stdlib.h> #define MAX 5void insert_by_priority(int);void delete_by_priority(int);void create();void check(int);void ...
0
votes
0answers
67 views

priority queue in JS

I am trying to use a priority Queue for my own data type which is a 3x3 array. The actual code and data type is more complex so I boiled it down to the essentials. Note that the priority queue works ...
9
votes
2answers
92 views

ArrayList.sort() vs PriorityQueue [duplicate]

I need to support a more inserts than reads and keep the data sorted. Which would be better performing:Using a PriorityQueue providing a comparator orUsing an ArrayList and calling .sort() after ...
1
vote
0answers
14 views

prority queue comparison and update

A possible solution is to mark the entry as removed and add a new entry with the revised priority. The documentation provides an example implementation: I am reading about priority queues in python ...
-2
votes
4answers
47 views

Java: How to access an instance variable in a ternary operator?

This is the ListNode class:public class ListNode {int val;ListNode next;ListNode(int x) { val=x; }}I am trying to initialize a PriorityQueue like this:PriorityQueue&...
2
votes
2answers
43 views

Can someone explain PriorityQueue in this example to me?

I am trying to learn how to use a PriorityQueue, as I have never used one before. Here is an example of one in use that I have found on LeetCode for a problem that finds the Top K elements in an array ...
-1
votes
0answers
18 views

Comparator not sorting a priority queue with a custom class [duplicate]

Currently the comparator is not sorting the queue i am trying to sort by Node's total_cost. We start with creating an empty queue using the comparator listed below, but when checking the queue in the ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,