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...
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. You will then attach priorityInsert(long key) and priorityRemove() methods). AND Use the provided PQDoublyLinkedTest.java to test your code. BOTH CODES SHOULD WORK TOGETHER, YOU JUST HAVE TO ADD priorityInsert(int). PLEASE PROVIDE...
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), and a driver...
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.
A priority queue is a special queue that adjusts the location of items based on some...
A priority queue is a special queue that adjusts the location of items based on some priority value. When inserted, a new value is placed in the queue ahead of every other item that has a lower priority than it. This gives us a queue that removes items from the front removing highest priority first, and from items with similar priority the ones that were inserted first. For example, if we inserted the following items with the priority {A, 1},...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT