This commit is contained in:
Lea Norgeux 2023-03-29 16:32:27 +02:00
commit 25bb414920

View file

@ -137,8 +137,35 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
@Override @Override
public void remove(E x) throws ElementNotFoundException { public void remove(E x) throws ElementNotFoundException {
// TODO: int i;
E lastE;
boolean notFound = true;
for(i = 0; i< this.currentSize; i++)
{
if(array.get(i).equals(x))
{
lastE = array.get(--currentSize);
this.arraySet(i, lastE);
notFound = false;
if(lastE.compareTo(x)>0)
{
percolateDown(i);
} }
else
{
percolateUp(i);
}
break;
}
}
if(notFound)
{
throw new ElementNotFoundException(x);
}
}
@Override @Override
public E findMin() throws EmptyPriorityQueueException { public E findMin() throws EmptyPriorityQueueException {