Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.53 KB | None | 0 0
  1. type 'a node = {
  2.   value: 'a;
  3.   successors: ('a node) list;
  4.   mutable tmp: exn
  5. }
  6.  
  7. open Graph
  8.  
  9. exception None
  10.  
  11. let rec a = {
  12.   value = "a";
  13.   successors = [b];
  14.   tmp = None
  15. }
  16. and b = {
  17.   value = "b";
  18.   successors = [a];
  19.   tmp = None
  20. };
  21.  
  22. exception Visited
  23.  
  24. let depth_first f n =
  25.   let rec aux n =
  26.     match n.tmp with
  27.     | Visited -> ()
  28.     | _ -> begin
  29.         f n.value;
  30.         n.tmp <- Visited;
  31.         List.iter aux n.successors
  32.     end
  33.   in
  34.   aux n
  35.  
  36. let _ =
  37.   depth_first print_string a;
  38.   print_newline ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement