Graphs_dart/tex/dart/graph/dfs.dart

19 lines
423 B
Dart
Raw Permalink Normal View History

2021-11-24 20:35:55 +03:00
List<bool>? dfsIterative(int v) {
v--;
List<bool> label = <bool>[];
for (int i = 0; i < _amount; i++) {
label.add(false);
}
List<int> stack = <int>[];
stack.add(v);
while (stack.isNotEmpty) {
v = stack.removeLast();
if (!label[v]) {
label[v] = true;
for (int i in _dots[v].getL().keys) {
stack.add(i - 1);
}
}
}
return label;
}