Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In java.util library, there is a very efficient implementation of Priority Queue ADT which is based on min binary heap (it's way more complicated
In java.util library, there is a very efficient implementation of Priority Queue ADT which is based on min binary heap (it's way more complicated and way more efficient than the normal binary heap and is called Fibonacci Heap). In order to use it, all you need is the following: To create an empty Priority Queue of String (for example), do this: PriorityQueue q = new PriorityQueue (); To insert an element to it, do this: q.add("new element"); To extract/remove the minimum value from it, do this: String minValue = q.remove(); To get the minimum value w/o removing it, do this: String minValue = q.peek(); To get the current size, do this: int size = q.size(); 2. Write a method that receives an array of integers and prints its elements in a sorted fashion (from highest to smallest). Hint: use PriorityQueue and a Stack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started