Courses‎ > ‎AP Computer Science 2‎ > ‎konstantinovich‎ > ‎

2018-04-26

posted Apr 25, 2018, 4:16 PM by Konstantinovich Samuel   [ updated Apr 30, 2018, 9:56 AM ]
Please Vote on the 15 different websites of my intro classes!
Just grade on style not on the actual content (don't read and base your rating on what they like)
(rate each one from 1-5, and give a 6 to whichever you think is the best)
https://goo.gl/forms/VYuOsyutL5iPudeo1

/12/MyHeap.java
You are writing a heap of Strings, you can always change it to a generic later.

 Constructors
 -MyHeap() - construct empty max heap
 -MyHeap(boolean) - true: construct empty max heap, false: construct empty min heap.
 Methods
 -void add(String s)
 -String remove()
 -String peek()
 -int size()

For generic comparables see this demo code: (let me know if there is anything more needed for the conversion to a generic.)



public class test<T extends Comparable<T>>{

        private T[] data;

        @SuppressWarnings("unchecked")
        public test(){
            data = (T[])new Comparable[10];

        }

        public void add(T value){
         data[0] = value;
        }
}
Comments