Just a few smaller issues:
- Why expose
buildHeap()when every other public method, including the constructors, already leaves you with a perfectly sorted heap? - Why does the
add()method contain sorting logic? This would usually be placed in anincrement()method. - An
increment()method is missing. - Your
add()method did not copy the element. Your heap is therefortherefore vulnerable to side effects where any of the elements you have a reference on, did get modified in the outside world. Either warn, watch, encapsulate or make immutable. - Comments? At least your constructors and public methods should be documented, denoting which side effects are to be expected.
- There is no interface to get the sorted list back.
- The
toString()method returns the internal order of the heap. Nice for debugging, but not what you would expect. You would expect it to return elements in lexicographical order. - Please don't use it in production. Your basic
MaxHeaphas significantly worse runtime characteristics than the default Fibonacci Heap. - There is a
getParent()helper, but you have omitted such helpers forgetLeft()andgetRight(), even though you are using the corresponding expressions multiple times.