Implement a priority queue capable of holding objects of an arbitrary type, T, by defining a PriorityQueue class that implements the queue with an ArrayList.A priority queue is a type of list where every item added to the queue also has an associated priority. Define priority in your application so that those items with the largest numerical value have the highest priority. Your class should support the following methods: . add (item, priority) –Adds a new item to the queue with the associated priority. remove () –Returns the item with the highest priority and removes it from the queue. If the user attempts to remove from an empty queue, return null. · tostring()-Returns a String representation of the priority queue. For example, if q is a priority queue defined to take strings q.add ("X", 10); q.add ("Y", 1); q.add ("Z", 3); System.out.println(q); // prints [ ["X",10], ["Y,1], ["Z",3] ] System.out.println(q.remove ()); // Returns X System.out.println (q.remove ()); // Returns Z System.out.println(q.remove ()) ; // Returns Y
Implement a priority queue capable of holding objects of an arbitrary type, T, by defining a PriorityQueue class that implements the queue with an ArrayList.A priority queue is a type of list where every item added to the queue also has an associated priority. Define priority in your application so that those items with the largest numerical value have the highest priority. Your class should support the following methods: . add (item, priority) –Adds a new item to the queue with the associated priority. remove () –Returns the item with the highest priority and removes it from the queue. If the user attempts to remove from an empty queue, return null. · tostring()-Returns a String representation of the priority queue. For example, if q is a priority queue defined to take strings q.add ("X", 10); q.add ("Y", 1); q.add ("Z", 3); System.out.println(q); // prints [ ["X",10], ["Y,1], ["Z",3] ] System.out.println(q.remove ()); // Returns X System.out.println (q.remove ()); // Returns Z System.out.println(q.remove ()) ; // Returns Y
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE:
The implementation of a queue in an array, as given in this chapter, uses the variable count to...
Related questions
Question
I need some help with this problem, more specifically, I don't really understand how to implement the actual array list and instance declaration such that the user can do things like this
PriorityQueue<Integer> queue1 = new PriorityQueue<>();
---
PriorityQueue<String> queue2 = new PriorityQueue<>();
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning