Tas binaire avec boucle for(similaire indexOf)
This commit is contained in:
parent
ea5d1d6e66
commit
4b9dbd1b30
2 changed files with 39 additions and 37 deletions
|
@ -137,7 +137,28 @@ 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:
|
if(this.isEmpty()){
|
||||||
|
throw new ElementNotFoundException(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
for(int i=0; i<this.currentSize;i++) {
|
||||||
|
if(this.array.get(i).equals(x)) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(index ==-1) {
|
||||||
|
throw new ElementNotFoundException(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
E lastItem = this.array.get(--this.currentSize);
|
||||||
|
this.arraySet(index, lastItem);
|
||||||
|
this.percolateDown(index);
|
||||||
|
this.percolateUp(index);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,20 +34,6 @@ public class Path {
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
Arc currentArc = null;
|
Arc currentArc = null;
|
||||||
|
|
||||||
for(int i=0; i<nodes.size()-1;i++) {
|
|
||||||
for(Arc a : nodes.get(i).getSuccessors()) {
|
|
||||||
if(a.getDestination().equals(nodes.get(i+1)) ) {
|
|
||||||
currentArc = a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(currentArc == null) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
currentArc = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
List<Arc> arcs = new ArrayList<Arc>();
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
double travelTime = 9999;
|
double travelTime = 9999;
|
||||||
|
|
||||||
|
@ -66,8 +52,12 @@ public class Path {
|
||||||
travelTime = a.getMinimumTravelTime();
|
travelTime = a.getMinimumTravelTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(currentArc == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
arcs.add(currentArc);
|
arcs.add(currentArc);
|
||||||
travelTime = 9999;
|
travelTime = 9999;
|
||||||
|
currentArc = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Path(graph, arcs);
|
return new Path(graph, arcs);
|
||||||
|
@ -89,21 +79,6 @@ public class Path {
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
Arc currentArc = null;
|
Arc currentArc = null;
|
||||||
|
|
||||||
for(int i=0; i<nodes.size()-1;i++) {
|
|
||||||
for(Arc a : nodes.get(i).getSuccessors()) {
|
|
||||||
if(a.getDestination().equals(nodes.get(i+1)) ) {
|
|
||||||
currentArc = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if(currentArc == null) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
currentArc = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
List<Arc> arcs = new ArrayList<Arc>();
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
float distanceMin = 9999;
|
float distanceMin = 9999;
|
||||||
|
|
||||||
|
@ -113,6 +88,7 @@ public class Path {
|
||||||
if(nodes.size() == 1) {
|
if(nodes.size() == 1) {
|
||||||
return new Path(graph, nodes.get(0) );
|
return new Path(graph, nodes.get(0) );
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i<nodes.size()-1;i++) {
|
for(int i=0; i<nodes.size()-1;i++) {
|
||||||
for(Arc a : nodes.get(i).getSuccessors()) {
|
for(Arc a : nodes.get(i).getSuccessors()) {
|
||||||
if(a.getLength() < distanceMin
|
if(a.getLength() < distanceMin
|
||||||
|
@ -121,9 +97,14 @@ public class Path {
|
||||||
distanceMin = a.getLength();
|
distanceMin = a.getLength();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(currentArc == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
arcs.add(currentArc);
|
arcs.add(currentArc);
|
||||||
distanceMin = 9999;
|
distanceMin = 9999;
|
||||||
|
currentArc = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Path(graph, arcs);
|
return new Path(graph, arcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue