mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 04:20:16 +08:00
Adding exception throws in case of handling empty heap.
This commit is contained in:
@ -84,6 +84,7 @@ public class MaxHeap implements Heap {
|
||||
|
||||
@Override
|
||||
public void deleteElement(int elementIndex) {
|
||||
if (isempty(maxHeap)) throw new EmptyHeapException("Attempt to delete an element from an empty heap");
|
||||
if ((elementIndex > maxHeap.size()) && (elementIndex <= 0)) throw new IndexOutOfBoundsException("Index out of heap range");
|
||||
// The last element in heap replaces the one to be deleted
|
||||
maxHeap.set(elementIndex - 1, getElement(maxHeap.size()));
|
||||
|
Reference in New Issue
Block a user