X Tutup
Skip to content

Commit ee9e4d9

Browse files
committed
minor
1 parent 177fb22 commit ee9e4d9

File tree

25 files changed

+74
-75
lines changed

25 files changed

+74
-75
lines changed

algorithm/etc/dp/fibonacci/code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
for (var i = 2; i < index; i++) {
22
D[i] = D[i - 2] + D[i - 1];
3-
tracer._select(i - 2, i - 1)._next();
4-
tracer._notify(i, D[i])._next();
3+
tracer._select(i - 2, i - 1)._wait();
4+
tracer._notify(i, D[i])._wait();
55
tracer._denotify(i);
66
tracer._deselect(i - 2, i - 1);
77
}

algorithm/etc/dp/longest_increasing_subsequence/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ for (var i = 1; i < 10; i++) {
99
tracer._select(i);
1010
logger._print(' LIS[' + i + '] = ' + LIS[i]);
1111
for (var j = 0; j < i; j++) {
12-
tracer._notify(j)._next();
12+
tracer._notify(j)._wait();
1313
tracer._denotify(j);
1414
if (A[i] > A[j] && LIS[i] < LIS[j] + 1) {
1515
LIS[i] = LIS[j] + 1;

algorithm/etc/dp/max_sum_path/code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ var N = DP.length;
22
var M = DP[0].length;
33
function update(i, j, value) {
44
DP[i][j] = value;
5-
dataViewer._select(i, j)._next();
6-
tracer._notify(i, j, DP[i][j])._next();
5+
dataViewer._select(i, j)._wait();
6+
tracer._notify(i, j, DP[i][j])._wait();
77
tracer._denotify(i, j);
88
dataViewer._deselect(i, j);
99
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var sum = D[0] + D[1] + D[2];
22
var max = sum;
33
tracer._select(0, 2);
4-
logger._print('sum = ' + sum)._next();
4+
logger._print('sum = ' + sum)._wait();
55
for (var i = 3; i < D.length; i++) {
66
sum += D[i] - D[i - 3];
77
if (max < sum) max = sum;
88
tracer._deselect(i - 3);
99
tracer._select(i);
10-
logger._print('sum = ' + sum)._next();
10+
logger._print('sum = ' + sum)._wait();
1111
}
12-
tracer._next()._deselect(D.length - 3, D.length - 1);
12+
tracer._deselect(D.length - 3, D.length - 1);
1313
logger._print('max = ' + max);

algorithm/graph_search/bellman_ford/shortest_path/code.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ function BELLMAN_FORD(src, dest) {
2020
for (var currentNode = 0; currentNode < G.length; currentNode++) {
2121
for (var currentNodeNeighbor = 0; currentNodeNeighbor <= G.length; currentNodeNeighbor++) {
2222
if (G [currentNode] [currentNodeNeighbor]) { //proceed to relax Edges only if a particular weight != 0 (0 represents no edge)
23-
logger._next()._print('Exploring edge from ' + currentNode + ' to ' + currentNodeNeighbor + ', weight = ' + G [currentNode] [currentNodeNeighbor]);
23+
logger._print('Exploring edge from ' + currentNode + ' to ' + currentNodeNeighbor + ', weight = ' + G [currentNode] [currentNodeNeighbor]);
2424

2525
if (weights [currentNodeNeighbor] > (weights [currentNode] + G [currentNode] [currentNodeNeighbor])) {
2626
weights [currentNodeNeighbor] = weights [currentNode] + G [currentNode] [currentNodeNeighbor];
2727
logger._print('weights [' + currentNodeNeighbor + '] = weights [' + currentNode + '] + ' + G [currentNode] [currentNodeNeighbor]);
2828
}
29-
tracer._visit(currentNodeNeighbor, currentNode, weights [currentNodeNeighbor]);
30-
tracer._next()._leave(currentNodeNeighbor, currentNode);
29+
tracer._visit(currentNodeNeighbor, currentNode, weights [currentNodeNeighbor])._wait();
30+
tracer._leave(currentNodeNeighbor, currentNode)._wait();
3131
}
3232
}
3333
}

algorithm/graph_search/bfs/shortest_path/code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ function BFS() {
88
}
99
W[s] = 0;
1010
Q.push(s); // add start node to queue
11-
tracer._visit(s, undefined, 0);
11+
tracer._visit(s, undefined, 0)._wait();
1212
while (Q.length > 0) {
1313
var node = Q.shift(); // dequeue
1414
for (i = 0; i < G[node].length; i++) {
1515
if (G[node][i]) { // if the edge from current node to the i-th node exists
1616
if (W[i] > W[node] + G[node][i]) { // if current path is shorter than the previously shortest path
1717
W[i] = W[node] + G[node][i]; // update the length of the shortest path
1818
Q.push(i); // add child node to queue
19-
tracer._next()._visit(i, node, W[i]);
19+
tracer._visit(i, node, W[i])._wait();
2020
}
2121
}
2222
}

algorithm/graph_search/bfs/tree/code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function BFS(s) { // s = start node
22
var Q = [];
33
Q.push(s); // add start node to queue
4-
tracer._visit(s);
4+
tracer._visit(s)._wait();
55
while (Q.length > 0) {
66
var node = Q.shift(); // dequeue
77
for (var i = 0; i < G[node].length; i++) {
88
if (G[node][i]) { // if current node has the i-th node as a child
99
Q.push(i); // add child node to queue
10-
tracer._next()._visit(i, node);
10+
tracer._visit(i, node)._wait();
1111
}
1212
}
1313
}

algorithm/graph_search/dfs/all_paths/code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function DFS(node, parent) { // node = current node, parent = previous node
2-
tracer._next()._visit(node, parent);
2+
tracer._visit(node, parent)._wait();
33
D[node] = true; // label current node as discovered
44
for (var i = 0; i < G[node].length; i++) {
55
if (G[node][i]) { // if the edge from current node to the i-th node exists
@@ -9,7 +9,7 @@ function DFS(node, parent) { // node = current node, parent = previous node
99
}
1010
}
1111
D[node] = false; // label current node as undiscovered
12-
tracer._next()._leave(node, parent);
12+
tracer._leave(node, parent)._wait();
1313
}
1414
var D; // D[i] indicates whether the i-th node is discovered or not
1515
for (var i = 0; i < G.length; i++) { // start from every node

algorithm/graph_search/dfs/shortest_path/code.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
function DFS(node, parent, weight) { // node = current node, parent = previous node
22
if (minWeight < weight) return;
33
if (node == e) {
4-
tracer._next()._visit(node, parent, weight);
5-
tracer._next()._leave(node, parent, 0);
4+
tracer._visit(node, parent, weight)._wait();
5+
tracer._leave(node, parent, 0)._wait();
66
if (minWeight > weight) {
77
minWeight = weight;
88
}
99
return;
1010
}
1111
D[node] = true; // label current node as discovered
12-
tracer._next()._visit(node, parent, weight);
12+
tracer._visit(node, parent, weight)._wait();
1313
for (var i = 0; i < G[node].length; i++) {
1414
if (G[node][i]) { // if the path from current node to the i-th node exists
1515
if (!D[i]) { // if the i-th node is not labeled as discovered
@@ -18,7 +18,7 @@ function DFS(node, parent, weight) { // node = current node, parent = previous n
1818
}
1919
}
2020
D[node] = false; // label current node as undiscovered
21-
tracer._next()._leave(node, parent, 0);
21+
tracer._leave(node, parent, 0)._wait();
2222
}
2323
var s = Math.random() * G.length | 0; // s = start node
2424
var e; // e = end node

algorithm/graph_search/dfs/tree/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function DFS(node, parent) { // node = current node, parent = previous node
2-
tracer._next()._visit(node, parent);
2+
tracer._visit(node, parent)._wait();
33
for (var i = 0; i < G[node].length; i++) {
44
if (G[node][i]) { // if current node has the i-th node as a child
55
DFS(i, node); // recursively call DFS

0 commit comments

Comments
 (0)
X Tutup