Untitled
unknown
plain_text
2 years ago
760 B
7
Indexable
protected List<E> visitDFPath(Vertex<E> v, Vertex<E> e, Set<Vertex<E>> visited, Set<E> blockedCells) {
if (v.equals(e)) {
List<E> path = new LinkedList<>();
path.add(e.getValue());
return path;
} else {
for (Vertex<E> neighbor : v.getNeighbors()) {
if (!visited.contains(neighbor) && !blockedCells.contains(neighbor.getValue())) {
visited.add(neighbor);
List<E> path = visitDFPath(neighbor, e, visited, blockedCells);
if (path != null) {
path.add(0, v.getValue());
return path;
}
}
}
return null;
}
}Editor is loading...