Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. fun odwiedz (i,odw,v, l) =
  2. let fun g [] = [] | g (h::t) = (odwiedz (h,odw,v,l); g t) in
  3. if (Array.sub (odw,i)) = 0 then
  4. (
  5. Array.update (odw,i,1);
  6. l := i::(!l);
  7. g (Vector.sub (v,i));
  8. []
  9. )
  10. else []
  11. end
  12.  
  13.  
  14.  
  15. fun dfs x =
  16. let val v = Vector.fromList x and i = ref 0 and n = length x and l = ref [] and odw = Array.array (length x, 0)
  17. in
  18. while !i <> n do
  19. (
  20. odwiedz (!i,odw,v, l);
  21. i := !i + 1
  22. );
  23. rev (!l)
  24. end
Add Comment
Please, Sign In to add comment