Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type 'a node = {
- value: 'a;
- successors: ('a node) list;
- mutable tmp: exn
- }
- open Graph
- exception None
- let rec a = {
- value = "a";
- successors = [b];
- tmp = None
- }
- and b = {
- value = "b";
- successors = [a];
- tmp = None
- };
- exception Visited
- let depth_first f n =
- let rec aux n =
- match n.tmp with
- | Visited -> ()
- | _ -> begin
- f n.value;
- n.tmp <- Visited;
- List.iter aux n.successors
- end
- in
- aux n
- let _ =
- depth_first print_string a;
- print_newline ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement