Skip to content

Commit 2e35586

Browse files
committed
sp
1 parent 92c90aa commit 2e35586

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Ch_4_4/TestDijkstraSP.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class TestDijkstraSP {
1010

1111
public static void main(String[] args) {
1212
_EdgeWeightedDigraph G = new _EdgeWeightedDigraph(new In("algdata/tinyEWD.txt"));
13+
StdOut.println(G);
1314
int s = 0;
1415
_DijkstraSP sp = new _DijkstraSP(G, s);
1516
for (int t = 0; t < G.V(); t++) {

Ch_4_4/_EdgeWeightedDigraph.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,17 @@ public Iterable<_DirectedEdge> edges() {
5959
}
6060
return bag;
6161
}
62+
63+
@Override
64+
public String toString() {
65+
StringBuilder s = new StringBuilder(V + " vertices, " + E + " edges\n");
66+
for (int v = 0; v < V; v++) {
67+
s.append(v).append(": ");
68+
for (_DirectedEdge e : adj(v)) {
69+
s.append(e.toString()).append(" ");
70+
}
71+
s.append("\n");
72+
}
73+
return s.toString();
74+
}
6275
}

Ch_4_4/note.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ edge relaxation
1313
if the length to w is larger than the sum of length to `v` plus weight of `v` to `w`,
1414
then `relax`: change `distTo[w] = distTo[v] + e.weight()` and `edgeTo[w] = e`.
1515

16+
![2020-05-12_003.jpg](https://gitee.com/gdhu/testtingop/raw/master/2020-05-12_003.jpg)
1617

18+
![2020-05-12_004.jpg](https://gitee.com/gdhu/testtingop/raw/master/2020-05-12_004.jpg)
1719

18-
20+
![2020-05-12_006.jpg](https://gitee.com/gdhu/testtingop/raw/master/2020-05-12_006.jpg)
1921

2022

2123

0 commit comments

Comments
 (0)