Skip to content

Instantly share code, notes, and snippets.

@Arrlindii
Created October 29, 2020 09:25
Show Gist options
  • Save Arrlindii/c7cccc41f6db688f10b92fc0c95388d3 to your computer and use it in GitHub Desktop.
Save Arrlindii/c7cccc41f6db688f10b92fc0c95388d3 to your computer and use it in GitHub Desktop.
func dfs(start: String, target: String) -> Bool{
visitedNodes.append(start)
print(start)
let directNodes = adjacencyList[start]!
for node in directNodes {
if node == target {
print("found the target movie: \(target)")
return true;
}
if (!visitedNodes.contains(node)) {
if (dfs(start: node, target: target)) {
return true;
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment