Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun bfs(startArticle: String, searchDepth: Int): Int {
- // first = ссылка, second = число шагов, за которое до неё можно дойти
- val articles: Queue<Pair<String, Int>> = LinkedList()
- articles.add(Pair(startArticle, 0))
- while (articles.isNotEmpty()) {
- val (ref, priority) = articles.poll()
- if (ref == HITLER) {
- return priority
- }
- if (priority == searchDepth) {
- continue
- }
- val wikipediaPages = searchRefs(getHtmlDocument(ref))
- for (page in wikipediaPages) {
- /* для отладки */ // println(page)
- if (page == HITLER) {
- return priority + 1
- }
- articles.add(Pair(page, priority + 1))
- }
- }
- return NOT_FOUND
- }
Add Comment
Please, Sign In to add comment