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
This commit is contained in:
committed by
Aditya Bhargava
parent
30bbe9cf01
commit
9dc7611411
39
06_breadth-first_search/julia/01_breadth-first_search.jl
Normal file
39
06_breadth-first_search/julia/01_breadth-first_search.jl
Normal file
@@ -0,0 +1,39 @@
|
||||
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
|
||||
"
|
||||
Reference in New Issue
Block a user