Files
grokking_algorithms/06_breadth-first_search/julia/01_breadth-first_search.jl
Massoud Afrashteh 9dc7611411 Julia samples (#108)
* Add julialang binary search sample

* Add unit test

* Add julialang selection sort sample

* Change julia suffix to jl

* Add recursion and quick sort with tests

* add quick sort

* Add hash table samples

* Add BFS

* Changed file names

* Add dijkstras

* Add Dijkstras test
2019-11-12 09:19:21 -06:00

40 lines
843 B
Julia

using DataStructures, Test, Suppressor
graph = Dict()
graph["you"] = ["alice","bob","claire"]
graph["bob"] = ["anuj","peggy"]
graph["claire"] = ["thom","jonny"]
graph["alice"] = ["peggy"]
graph["anuj"] = []
graph["peggy"] = []
graph["thom"] = []
graph["jonny"] = []
function person_is_seller(name)
return name[end] == 'm'
end
function search(name)
search_queue = Deque{String}()
map(n -> push!(search_queue,n),graph[name])
searched = []
while isempty(search_queue) == false
person = popfirst!(search_queue)
if (person in searched) == false
if person_is_seller(person)
println(person , " is a mango seller")
return true
else
map(n -> push!(search_queue,n),graph[person])
push!(searched,person)
end
end
end
return false
end
result = @capture_out search("you")
@test result == "thom is a mango seller
"