I've also added a constructor that takes the contents of a Java Collection and adds it to the heap en masse, for convenience and efficiency.
Something to remember here when implementing remove: make sure that the last element of the heap is added to the top of the heap, not swapped with that element. Using swap is almost guaranteed to break the heap property constraint! This took me a while to debug.
Something to remember here when implementing remove: make sure that the last element of the heap is added to the top of the heap, not swapped with that element. Using swap is almost guaranteed to break the heap property constraint! This took me a while to debug.
No comments:
Post a Comment