Commit fc40fc7d authored by charguer's avatar charguer

dfstest

parent 87e1c36f
......@@ -4,7 +4,7 @@ open HeapSig
module LeftistHeap (Element : Ordered) : Heap =
(* (Heap with module Element = Element) *)
struct
structs
module Element = Element
(*todo*)
......
(*************************************************************************)
(** Graph representation by adjacency lists *)
......@@ -32,6 +36,42 @@ let fold_nodes (g:'a t) (a:'b) (f:'b->int->'b) =
end
type color = White | Gray | Black
(*
let reachable_recursive g a b =
let n = GraphAdj.nb_nodes g in
let c = Array.make n White in
visit a;
c.(b)
*)
let rec dfs_from g c i =
let rec visit i =
c.(i) <- Gray;
GraphAdj.iter_edges_target_of g i (fun j ->
if c.(j) = White
then visit j);
c.(i) <- Black;
in
visit i
let dfs_main (g : unit GraphAdj.t) =
let n = GraphAdj.nb_nodes g in
let c = Array.make n White in
for i = 0 to n - 1 do
if c.(i) = White then
dfs_from g c i
done
(*
(*************************************************************************)
(** GraphAdj representation by adjacency matrix --LATER *)
......@@ -230,6 +270,16 @@ let connected_warshall_floyd g =
done;
done
(* TODO:
for each node
if node not marked
nbcompo++
foreach neighbor
mark it
*)
(*************************************************************************)
(** Strongly connected components, Kosaraju's algorithm (2 DFS) *)
......@@ -248,3 +298,4 @@ let connected_warshall_floyd g =
(*************************************************************************)
(** Eulerian path *)
*)
\ No newline at end of file
# Possible to define "ML" to be the list of source files to consider
include ../Makefile.example
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment