Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
614 B
0
Indexable
Never
    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 found