clean up BFS function
This commit is contained in:
parent
78c5cd5639
commit
cfed832b8b
12
main.jl
12
main.jl
@ -74,17 +74,21 @@ function LevenshteinNeighbours(w::String)
|
||||
return neighbours
|
||||
end
|
||||
|
||||
function BFS(graph::Vector{node})
|
||||
function BFS(g::Vector{node})
|
||||
graph = deepcopy(g)
|
||||
components = 0
|
||||
biggestComponent = 0
|
||||
|
||||
q = Queue{node}()
|
||||
|
||||
for i in eachindex(graph)
|
||||
if graph[i].colored == false
|
||||
|
||||
components += 1
|
||||
currComponent = 1
|
||||
enqueue!(q, graph[i])
|
||||
graph[i].colored = true
|
||||
|
||||
while !isempty(q)
|
||||
n = dequeue!(q)
|
||||
for m in n.neighbours
|
||||
@ -95,14 +99,16 @@ function BFS(graph::Vector{node})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
biggestComponent = max(biggestComponent, currComponent)
|
||||
if biggestComponent == currComponent
|
||||
println("Wort: ", graph[i].word)
|
||||
println("Wort in der größten Komponente: ", graph[i].word)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return components, biggestComponent
|
||||
println("Anzahl Zusammenhangskomponenten: ", components)
|
||||
println("Größe der größten Zusammenhangskomponente: ", biggestComponent)
|
||||
end
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user