Untitled
unknown
plain_text
3 years ago
614 B
10
Indexable
create a Queue<String> and initialize it with urlFrom
create a HashMap<String, Integer> to track the distance from urlFrom
distance[urlFrom] = 0
while queue is not empty do
currentUrl = queue.poll()
if currentUrl equals urlTo then
return distance[currentUrl]
end if
for each neighbor in graph[currentUrl] do
if neighbor is not in distance.keys then
queue.add(neighbor)
distance[neighbor] = distance[currentUrl] + 1
end if
end for
end while
return -1 // no path foundEditor is loading...