This is the problem i was given. I\'m not looking for theanswer to this problem
ID: 3618274 • Letter: T
Question
This is the problem i was given. I'm not looking for theanswer to this problem just an explanation or example of somesort. I don't understand what it means to assume that type Eimplements comparable interface. Also is E supposed to be thegeneric type? Your help would be appreciated.In the second part, you will implement a MIN heap and MAX heap datastructure, and a heap sort algorithm by leveraging your own heapimplementation. Your class name must be Heap, and the classprovides a constructor, Heap (boolean minHeap), which takes aBoolean input argument and constructs a MIN-heap if true andconstructs a MAX-heap if false. Your implementation must use ageneric type, must assume that the type E implements Comparableinterface in Java, may not hardcode your own comparison function,and must use recursive algorithms.
There are also methods that must be included:
boolean insert (E item): inserts an item into the queue. Returnstrue if successful; returns false; if the item could not beinsert.
E remove (): removes the smallest (in MIN heap) /largest entry (inMAX heap) and returns it if the heap is not empty. If the heap isempty; throw a NoSuchElementException.
E peek(): returns the smallest (in MIN heap) / largest entry (inMAX heap). If the heap is empty, returns null.
List<E> sort (E[] items): implement a HEAP sort by using theinsert and remove functions you have implemented. The sorted itemsmust be returned as a List<E> type object.
Explanation / Answer
I think this will help you alot. http://java.sun.com/developer/technicalArticles/J2SE/generics/
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.