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
|
return neighbours
|
||||||
end
|
end
|
||||||
|
|
||||||
function BFS(graph::Vector{node})
|
function BFS(g::Vector{node})
|
||||||
|
graph = deepcopy(g)
|
||||||
components = 0
|
components = 0
|
||||||
biggestComponent = 0
|
biggestComponent = 0
|
||||||
|
|
||||||
q = Queue{node}()
|
q = Queue{node}()
|
||||||
|
|
||||||
for i in eachindex(graph)
|
for i in eachindex(graph)
|
||||||
if graph[i].colored == false
|
if graph[i].colored == false
|
||||||
|
|
||||||
components += 1
|
components += 1
|
||||||
currComponent = 1
|
currComponent = 1
|
||||||
enqueue!(q, graph[i])
|
enqueue!(q, graph[i])
|
||||||
graph[i].colored = true
|
graph[i].colored = true
|
||||||
|
|
||||||
while !isempty(q)
|
while !isempty(q)
|
||||||
n = dequeue!(q)
|
n = dequeue!(q)
|
||||||
for m in n.neighbours
|
for m in n.neighbours
|
||||||
@ -95,14 +99,16 @@ function BFS(graph::Vector{node})
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
biggestComponent = max(biggestComponent, currComponent)
|
biggestComponent = max(biggestComponent, currComponent)
|
||||||
if biggestComponent == currComponent
|
if biggestComponent == currComponent
|
||||||
println("Wort: ", graph[i].word)
|
println("Wort in der größten Komponente: ", graph[i].word)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return components, biggestComponent
|
println("Anzahl Zusammenhangskomponenten: ", components)
|
||||||
|
println("Größe der größten Zusammenhangskomponente: ", biggestComponent)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user