From f00d27589b30ce97aeb4507757e47a121c03d1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BE=D1=80=D0=BE=D0=B7=D0=BE=D0=B2=20=D0=90=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=B5=D0=B9?= Date: Tue, 26 Oct 2021 11:49:01 +0000 Subject: [PATCH] DFS --- bin/src/graph.dart | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/src/graph.dart b/bin/src/graph.dart index 8778490..8cd0c20 100644 --- a/bin/src/graph.dart +++ b/bin/src/graph.dart @@ -478,8 +478,30 @@ class Graphs { path = path.reversed.toList(); //print("Shortest path between vertices ${startDot+1} and ${goalDot+1} is: $path"); - if (path[0]==startDot && path[1]==goalDot && !_dots[startDot].hasConnection(goalDot+1)) return null; + if (path[0] == (startDot+1) && + path[1] == (goalDot+1) && + !_dots[startDot].hasConnection(goalDot + 1)) return null; return path; } + + List? dfsIterative(int v) { + v--; + List label = []; + for (int i = 0; i < _amount; i++) { + label.add(false); + } + List stack = []; + 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; + } //************Алгоритмы************ }