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).
What are the differences between a maximum priority queue and a minimum priority queue?
What are the differences between a maximum priority queue and a minimum priority queue?
JAVA DATA STRUCTURE (Linked Lists/Queue) public class Node {    int value;    Node nextNode;   ...
JAVA DATA STRUCTURE (Linked Lists/Queue) public class Node {    int value;    Node nextNode;    Node(int v, Node n){        value = v;        nextNode = n;    }    Node (int v){        this(v,null);    } } public class Stack {    protected Node top;    Stack(){        top = null;    }    boolean isEmpty(){        return( top == null);    }    void push(int v){        Node tempPointer;       ...
Implement the minimum priority queue UnsortedMPQ (using vector) that is a child class of the provided...
Implement the minimum priority queue UnsortedMPQ (using vector) that is a child class of the provided MPQ class. The functions from MPQ that are virtual function (remove min(), is empty(), min(), and insert()) must be implemented in the child classes. The functions remove min() and min() should throw an exception if the minimum priority queue is empty. For the UnsortedMPQ class, you will use a vector to implement the minimum priority queue functions. The insert() function should be O(1) and...
Say that we want to maintain both a Queue and a Priority Queue. This means that...
Say that we want to maintain both a Queue and a Priority Queue. This means that when you do Enqueue you also add the item to the Priority Queue and when you do Dequeue you also remove the item from the Priority Queue. And vise-versa. Show how to do it. Write pseudo codes or explain in words and the running time.
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...
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
#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,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT