Launch.java fini et BinaryHeap Remove() fini
This commit is contained in:
parent
b4275ae5a6
commit
870726461b
3 changed files with 20 additions and 9 deletions
|
|
@ -83,7 +83,6 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
||||||
|
|
||||||
this.arraySet(index, x);
|
this.arraySet(index, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method to percolate down in the heap.
|
* Internal method to percolate down in the heap.
|
||||||
*
|
*
|
||||||
|
|
@ -138,6 +137,14 @@ 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:
|
// TODO:
|
||||||
|
int index = array.indexOf(x);
|
||||||
|
if (isEmpty() || index < 0 || index >= this.currentSize) {
|
||||||
|
throw new ElementNotFoundException(x);
|
||||||
|
}
|
||||||
|
E lastItem = this.array.get(--this.currentSize);
|
||||||
|
this.arraySet(index,lastItem);
|
||||||
|
this.percolateUp(index);
|
||||||
|
this.percolateDown(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import org.insa.graphs.gui.drawing.components.BasicDrawing;
|
||||||
import org.insa.graphs.model.Graph;
|
import org.insa.graphs.model.Graph;
|
||||||
import org.insa.graphs.model.Path;
|
import org.insa.graphs.model.Path;
|
||||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||||
|
import org.insa.graphs.model.io.BinaryPathReader;
|
||||||
import org.insa.graphs.model.io.GraphReader;
|
import org.insa.graphs.model.io.GraphReader;
|
||||||
import org.insa.graphs.model.io.PathReader;
|
import org.insa.graphs.model.io.PathReader;
|
||||||
|
|
||||||
|
|
@ -46,28 +47,31 @@ public class Launch {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
// Visit these directory to see the list of available files on Commetud.
|
// Visit these directory to see the list of available files on Commetud.
|
||||||
final String mapName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
final String mapName = "C:/Users/guill/OneDrive/Bureau/Graphes/GraphesGit/Cartes/insa.mapgr";
|
||||||
final String pathName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
|
final String pathName = "C:/Users/guill/OneDrive/Bureau/Graphes/GraphesGit/Cartes/paths/path_fr31insa_rangueil_r2.path";
|
||||||
|
|
||||||
// Create a graph reader.
|
// Create a graph reader.
|
||||||
final GraphReader reader = new BinaryGraphReader(
|
final GraphReader reader = new BinaryGraphReader(
|
||||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
||||||
|
|
||||||
// TODO: Read the graph.
|
// TODO: Read the graph.
|
||||||
final Graph graph = null;
|
final Graph graph = reader.read();
|
||||||
|
|
||||||
// Create the drawing:
|
// Create the drawing:
|
||||||
final Drawing drawing = createDrawing();
|
final Drawing drawing = createDrawing();
|
||||||
|
|
||||||
// TODO: Draw the graph on the drawing.
|
// TODO: Draw the graph on the drawing.
|
||||||
|
drawing.drawGraph(graph);
|
||||||
|
|
||||||
// TODO: Create a PathReader.
|
// TODO: Create a PathReader.
|
||||||
final PathReader pathReader = null;
|
final PathReader pathReader = new BinaryPathReader(
|
||||||
|
new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
|
||||||
|
|
||||||
// TODO: Read the path.
|
// TODO: Read the path.
|
||||||
final Path path = null;
|
final Path path = pathReader.readPath(graph);
|
||||||
|
|
||||||
// TODO: Draw the path.
|
// TODO: Draw the path.
|
||||||
|
drawing.drawPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public class Path {
|
||||||
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
List<Arc> arcs = new ArrayList<Arc>();
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
// TODO:
|
// DONE:
|
||||||
if (nodes.size() == 1) {
|
if (nodes.size() == 1) {
|
||||||
return new Path(graph,nodes.get(0));
|
return new Path(graph,nodes.get(0));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue