marker[u] = cycle_number should be marker[cur] = cycle_number, otherwise, it is missing a vertex in each cycle. cycle_number must be a global variable. You can avoid the global by returning the number of cycles created in the recursive call.
Note that if two cycles share a vertex, this vertex will only be print in one cycle, you should store the cycles as you find these. And you will not get all cycles, only a basis (but you will spot every vertex belonging to a cycle).
Here is the code I get:
function DFS_Out_cycle!(u, p, colour, marker, parent, cycle_number, adj_list)
# global cycle_number
if colour[u] == "BLACK"
return cycle_number
end
if colour[u] == "GRAY"
cycle_number += 1
cur = p
marker[cur] = cycle_number
while cur != u
cur = parent[cur]
marker[cur] = cycle_number
end
return cycle_number
end
parent[u] = p
colour[u] = "GRAY"
for v in adj_list[u]
if v == parent[u]
continue
end
cycle_number = DFS_Out_cycle!(v, u, colour, marker, parent, cycle_number, adj_list)
end
colour[u] = "BLACK"
return cycle_number
end
function print_dfs_cycles!(adj_list, marker, cycles_list)
for i in 0:length(adj_list)
if marker[i] != 0
push!(cycles_list[marker[i]], i)
end
end
for (i, l) in enumerate(cycles_list)
println("Cycle $i : $l")
end
end
g = Graph(13); add_edge!(g,1,2); add_edge!(g,2,3); add_edge!(g,3,4); add_edge!(g,3,5); add_edge!(g,5,6); add_edge!(g,4,6); add_edge!(g,4,7);
add_edge!(g,7,8); add_edge!(g,6,10); add_edge!(g,5,9); add_edge!(g,10,11); add_edge!(g,11,12); add_edge!(g,11,13); add_edge!(g,12,13);
g_l = g.fadjlist
# g_l = adjacency_list(g);
cycle_number = 0;
marker = Dict(i=>0 for i in 0:length(g_l));
parent = Dict(i=>0 for i in 0:length(g_l));
colour = ["WHITE" for key ∈ keys(g_l)]
cycle_number = DFS_Out_cycle!(1, 0, colour, marker, parent, cycle_number, g_l);
cycles_list = [Int[] for i in 1:cycle_number];
print_dfs_cycles!(g_l, marker, cycles_list)