Skip to content

Commit 1cbba2c

Browse files
committed
some fixes from Jean-Francois
1 parent c492fe5 commit 1cbba2c

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

CCSPiJ/src/chapter4/Graph.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@
2525
// E is the type of the edges
2626
public abstract class Graph<V, E extends Edge> {
2727

28-
private ArrayList<V> vertices;
29-
protected ArrayList<ArrayList<E>> edges;
28+
private ArrayList<V> vertices = new ArrayList<>();
29+
protected ArrayList<ArrayList<E>> edges = new ArrayList<>();
3030

3131
public Graph() {
32-
vertices = new ArrayList<>();
33-
edges = new ArrayList<>();
3432
}
3533

3634
public Graph(List<V> vertices) {
37-
this.vertices = new ArrayList<>(vertices);
38-
edges = new ArrayList<>();
39-
for (V vertice : vertices) {
35+
this.vertices.addAll(vertices);
36+
for (V vertex : vertices) {
4037
edges.add(new ArrayList<>());
4138
}
4239
}
@@ -95,7 +92,7 @@ public List<E> edgesOf(V vertex) {
9592
public String toString() {
9693
StringBuilder sb = new StringBuilder();
9794
for (int i = 0; i < getVertexCount(); i++) {
98-
sb.append(vertexAt(i).toString());
95+
sb.append(vertexAt(i));
9996
sb.append(" -> ");
10097
sb.append(Arrays.toString(neighborsOf(i).toArray()));
10198
sb.append(System.lineSeparator());

CCSPiJ/src/chapter4/WeightedGraph.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void addEdge(V first, V second, float weight) {
5151
public String toString() {
5252
StringBuilder sb = new StringBuilder();
5353
for (int i = 0; i < getVertexCount(); i++) {
54-
sb.append(vertexAt(i).toString());
54+
sb.append(vertexAt(i));
5555
sb.append(" -> ");
5656
sb.append(Arrays.toString(edgesOf(i).stream()
5757
.map(we -> "(" + vertexAt(we.v) + ", " + we.weight + ")").toArray()));

0 commit comments

Comments
 (0)