-
Notifications
You must be signed in to change notification settings - Fork 1
/
dfs.js
28 lines (28 loc) · 809 Bytes
/
dfs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module.exports = {
dfs(nodes, links) {
stack = [];
used = [];
for(i = 0; i < nodes.length; i++) {
used.push(false);
};
function search(current) {
stack.push(current);
used[current] = true;
links.forEach(link => {
if(link.from == current) {
if(stack.includes(link.to) && nodes[link.to].type == 'incremental') {
link.out = 'loop';
}
if(!used[link.to])
search(link.to);
}
});
stack.pop();
}
for(i = 0; i < nodes.length; i++) {
if(nodes[i].type == 'terminator')
search(i);
};
return links;
}
}