Skip to content

Commit b0dde27

Browse files
committed
Add SSSP tables to js
1 parent 160d68b commit b0dde27

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

javascript/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,11 +1187,11 @@ console.log('\nSection 24.1 - Bellman-Ford Algorithm (Single-Source Shortest Pat
11871187

11881188
G = new WeightedGraph();
11891189
G.addDirectedEdge(new GraphVertexSSSP('s'), new GraphVertexSSSP('y'), 7); // cf. Figure 24.4, p. 652
1190-
G.addDirectedEdge(G.V['s'], new GraphVertexSSSP('t'), 6);
1191-
G.addDirectedEdge(G.V['t'], new GraphVertexSSSP('x'), 5);
1190+
G.addDirectedEdge(new GraphVertexSSSP('x'), new GraphVertexSSSP('t'), -2);
1191+
G.addDirectedEdge(G.V['s'], G.V['t'], 6);
11921192
G.addDirectedEdge(G.V['t'], G.V['y'], 8);
11931193
G.addDirectedEdge(G.V['t'], new GraphVertexSSSP('z'), -4);
1194-
G.addDirectedEdge(G.V['x'], G.V['t'], -2);
1194+
G.addDirectedEdge(G.V['t'], G.V['x'], 5);
11951195
G.addDirectedEdge(G.V['y'], G.V['x'], -3);
11961196
G.addDirectedEdge(G.V['y'], G.V['z'], 9);
11971197
G.addDirectedEdge(G.V['z'], G.V['x'], 7);
@@ -1209,6 +1209,14 @@ console.log(
12091209

12101210
let isReachable = bellmanFord(G, G.V['s']);
12111211
console.log('\nSingle-source shortest path:\n');
1212+
console.log('v | v.pi | v.d ');
1213+
console.log('---|------|-----');
1214+
for(let v in G.V) {
1215+
(v !== 's')
1216+
? console.log(`${G.V[v].key} ${G.V[v].pi.key} ${G.V[v].d}`)
1217+
: console.log(`${G.V[v].key} ${' '} ${G.V[v].d}`);
1218+
}
1219+
console.log();
12121220
console.log(
12131221
` t,${G.V['t'].d} ${arrows.l}-2${arrows.l} x,${G.V['x'].d}`
12141222
+ `\n ${arrows.dr} ${arrows.ur}`
@@ -1247,6 +1255,14 @@ console.log(
12471255

12481256
dijkstra(G, G.V['s']);
12491257
console.log('\nSingle-source shortest path:\n');
1258+
console.log('v | v.pi | v.d ');
1259+
console.log('---|------|-----');
1260+
for(let v in G.V) {
1261+
(v !== 's')
1262+
? console.log(`${G.V[v].key} ${G.V[v].pi.key} ${G.V[v].d}`)
1263+
: console.log(`${G.V[v].key} ${' '} ${G.V[v].d}`);
1264+
}
1265+
console.log();
12501266
console.log(
12511267
` t,${G.V['t'].d} ${arrows.r}1${arrows.r} x,${G.V['x'].d}`
12521268
+ `\n ${arrows.u}`

0 commit comments

Comments
 (0)