You may use the Java Libraries for solving this problem. We recommend using java.util.* The star “ * ” acts as a wildcard and allows you to use the entire java.util library. The heap presented in the screenshot is also known as a max-heap, in which each node is greater than or equal to any of it's children. A min-heap is a heap in which each node is less than or equal to any of its children. Min-heaps are often used to implement priority queues. Revise the Heap class in the screenshot to implement a min-heap. (The max heap example begins on the screenshot that says "Listings 23.9" at the top). Use the following logic:
PLEASE READ THIS FIRST! _____________________
Please write in java. Add comments but make the comments short. No need for really long comments. Please keep code very neat and simple , dont add anything unneccesary in the code if you weren't instructed to do so. If youve answered this before please dont copy and paste from a previous question! (Rewrite it in another way)..... Also be sure to read the instructions below carefully. The two files that are attached are screenshots of the textbook's MAX-HEAP Example. You will be creating a mini-heap from that example. But the Instructions below explains everything you'll be doing. NO THIS is not a homework assignment, it's practice work. Please type the code out so that I can copy and paste it into my IDE and see the output for my self but also still provide a screenshot of your output!
INSTRUCTIONS FOR QUESTION BELOW!!_____________________________
You may use the Java Libraries for solving this problem. We recommend using java.util.* The star “ * ” acts as a wildcard and allows you to use the entire java.util library.
The heap presented in the screenshot is also known as a max-heap, in which each node is greater than or equal to any of it's children. A min-heap is a heap in which each node is less than or equal to any of its children. Min-heaps are often used to implement priority queues. Revise the Heap class in the screenshot to implement a min-heap. (The max heap example begins on the screenshot that says "Listings 23.9" at the top).
Use the following logic:
- Write a main method that will accept 5 numbers, and put them in a min-heap
- Remove them from the min heap, printing one at a time as they are removed, to show that the list is sorted
Hint: The screenshotted textbook example is for a MAX heap; you must alter that example to reflect a MIN heap – think about it !
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 6 images