We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent eff324a commit 53e3385Copy full SHA for 53e3385
2018/pathfinding.py
@@ -172,6 +172,25 @@ def add_walls(self, vertices):
172
173
return changed
174
175
+ def dfs_groups(self):
176
+ """
177
+ Groups vertices based on depth-first search
178
+
179
+ :return: A list of groups
180
181
+ groups = []
182
+ unvisited = self.vertices.copy()
183
184
+ while unvisited:
185
+ start = unvisited.pop()
186
+ self.depth_first_search(start)
187
188
+ newly_visited = list(self.distance_from_start.keys())
189
+ unvisited = [x for x in unvisited if x not in newly_visited]
190
+ groups.append(newly_visited)
191
192
+ return groups
193
194
def depth_first_search(self, start, end=None):
195
"""
196
Performs a depth-first search based on a start node
0 commit comments