Question

In: Computer Science

Use a priority queue to simulate prioritized jobs Priority Queue class Queue Class Node Class (Node...

Use a priority queue to simulate prioritized jobs

  • Priority Queue class
    • Queue Class
    • Node Class (Node will have a 4 digit job number and a priority (A, B, etc) with A highest priority
  • In the driver
    • Create a priority queue object
    • Add 3 jobs of 'B' priority
    • Add 4 jobs of 'D' priority
    • Add 2 jobs of highest priority
    • Print the queue

Solutions

Expert Solution

// Java

// if you have any problem let me know i will try to help you. Thank you.


import java.util.Comparator;
import java.util.PriorityQueue;

class Node implements Comparator<Node>{
        int jobNumber;
        char priority;
        Node(int n,char prio)
        {
                jobNumber=n;
                priority=prio;
        }
        Node()
        {
                
        }
        @Override
        public int compare(Node o1, Node o2) {
        
                return o1.priority-o2.priority;
        }
        
}
public class Main {

        public static void main(String[] args) {
                PriorityQueue<Node> pq=new PriorityQueue<Node>(new Node());
                // Add 3 jobs of B priority
                pq.add(new Node(1234,'B'));
                pq.add(new Node(1854,'B'));
                pq.add(new Node(1658,'B'));
                
                // 4 jobs of D priority
                pq.add(new Node(1584,'D'));
                pq.add(new Node(1934,'D'));
                pq.add(new Node(2534,'D'));
                pq.add(new Node(8234,'D'));
                // Add 2 jobs of highest priority
                pq.add(new Node(7854,'A'));
                pq.add(new Node(9854,'A'));
                
                //printing  the queue
                while(!pq.isEmpty())
                {
                        Node temp=pq.poll();
                        System.out.println(temp.jobNumber+" "+temp.priority);
                }
                                
        }

}

// Sample output:-


Related Solutions

Implement a priority queue using a DoublyLinkedList where the node with the highest priority (key) is...
Implement a priority queue using a DoublyLinkedList where the node with the highest priority (key) is the right-most node. The remove (de-queue) operation returns the node with the highest priority (key). If displayForward() displays List (first-->last) : 10 30 40 55 remove() would return the node with key 55. Demonstrate by inserting keys at random, displayForward(), call remove then displayForward() again. You will then attach a modified DoublyLinkedList.java (to contain the new priorityInsert(long key) and priorityRemove() methods). Use the provided...
Priority Queue Application: Use your Java's Priority Queue. Make a priority queue to represent customers being...
Priority Queue Application: Use your Java's Priority Queue. Make a priority queue to represent customers being served at the Department of Motor Vehicles. Start with 100 customers in a List. In a loop, generate a priority for each customer (1-5) In a second loop, add the users to a priority queue Print the List and the Priority Queue
Write a java class for a Priority Queue. Use an arraylist, and include enque, deque, and...
Write a java class for a Priority Queue. Use an arraylist, and include enque, deque, and a method to get all the values of the queue. (This is not writing a file implementing the java class PriorityQueue, but rather you are writing a program that is a priority queue).
How to write a max-heap implementation of a templated priority queue class using the STL std::vector...
How to write a max-heap implementation of a templated priority queue class using the STL std::vector class to hold the data array
Language C++ Implement a Priority Queue with a Binary HEAP. Use a Max Heap. Create a...
Language C++ Implement a Priority Queue with a Binary HEAP. Use a Max Heap. Create a class called Node: Have a Name and Priority.Data set - 10 is the highest priority, 1 is lowest priority. Enqueue and dequeue in the following order. Function  Name, Priority Enqueue  Joe, 3 Enqueue  Fred,1 Enqueue Tuyet,9 Enqueue  Jose, 6 Dequeue Enqueue  Jing, 2 Enqueue  Xi, 5 Enqueue  Moe, 3 DequeueEnqueue  Miko, 7 Enqueue Vlady, 8 Enqueue Frank, 9 Enqueue  Anny, 3 DequeueEnqueue  Xi, 2 Enqueue  Wali, 2 Enqueue  xChe, 6 Enqueue  xVerra, 8 Dequeue Dequeue Dequeue Dequeue...
#include <iostream> #include <queue> //This contains the STL's efficient implementation of a priority queue using a...
#include <iostream> #include <queue> //This contains the STL's efficient implementation of a priority queue using a heap using namespace std; /* In this lab you will implement a data structure that supports 2 primary operations: - insert a new item - remove and return the smallest item A data structure that supports these two operations is called a "priority queue". There are many ways to implement a priority queue, with differernt efficiencies for the two primary operations. For this lab,...
public class MyLinked {    static class Node {        public Node (double item, Node...
public class MyLinked {    static class Node {        public Node (double item, Node next) { this.item = item; this.next = next; }        public double item;        public Node next;    }    int N;    Node first;     // remove all occurrences of item from the list    public void remove (double item) {        // TODO    } Write the remove function. Do NOT add any fields to the node/list classes, do...
Implement a Priority Queue (PQ) using an UNSORTED LIST. Use an array size of 10 elements....
Implement a Priority Queue (PQ) using an UNSORTED LIST. Use an array size of 10 elements. Use a circular array: Next index after last index is 0. Add the new node to next available index in the array. When you add an element, add 1 to index (hit max index, go to index 0). Test if array in full before you add. When you remove an element, from the list, move the following elements to the left to fill in...
Define empty methods in Queue class using LinkedList class in Java ------------------------------------------------------------------------------- //Queue class public class...
Define empty methods in Queue class using LinkedList class in Java ------------------------------------------------------------------------------- //Queue class public class Queue{ public Queue(){ // use the linked list } public void enqueue(int item){ // add item to end of queue } public int dequeue(){ // remove & return item from the front of the queue } public int peek(){ // return item from front of queue without removing it } public boolean isEmpty(){ // return true if the Queue is empty, otherwise false }...
write C program to implement the priority queue with the operation insert
write C program to implement the priority queue with the operation insert
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT