Graphs_dart/tex/dart/graph/dfs.dart

19 lines
423 B
Dart

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;
}