Implémentation du remove faite
This commit is contained in:
parent
44de56129e
commit
1e63964e41
2 changed files with 34 additions and 1 deletions
|
@ -137,7 +137,40 @@ 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:
|
boolean trouve=false;
|
||||||
|
E element;
|
||||||
|
for(int i=0;i<this.currentSize;i++)
|
||||||
|
{
|
||||||
|
if(trouve)
|
||||||
|
{
|
||||||
|
if(i!=this.currentSize-1)
|
||||||
|
{ element = this.array.get(i);
|
||||||
|
this.array.set(i,this.array.get(i+1));
|
||||||
|
this.array.set(i+1,element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(x==this.array.get(i))
|
||||||
|
{
|
||||||
|
trouve=true;
|
||||||
|
if(i!=this.currentSize-1)
|
||||||
|
{ element = this.array.get(i);
|
||||||
|
this.array.set(i,this.array.get(i+1));
|
||||||
|
this.array.set(i+1,element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!trouve)
|
||||||
|
{
|
||||||
|
throw new ElementNotFoundException(x);
|
||||||
|
}
|
||||||
|
this.currentSize--;
|
||||||
|
for(int i=0;i<this.currentSize;i++)
|
||||||
|
{
|
||||||
|
this.percolateDown(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue