Created
October 29, 2020 09:25
-
-
Save Arrlindii/c7cccc41f6db688f10b92fc0c95388d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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