Advertisement
jasio1906

dfs

Jan 16th, 2020
1,155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.66 KB | None | 0 0
  1. let dfs mat start finish =
  2.         let n = Array.length mat in
  3.         let visited = Array.make n 0 in
  4.         let lista = ref [start] in
  5.         let flague = ref false in
  6.         while (!lista <> [] && !flague <> true)
  7.         do
  8.                 let cur= List.hd !lista in
  9.                 lista:= List.tl !lista;
  10.                 for i = 0 to n-1 do
  11.                         if(mat.(cur).(i)=1 && visited.(i)=0) then
  12.                                 if i=finish then (flague:=true;)
  13.                                 else
  14.                                 (visited.(i)<-1;
  15.                                 lista:=i::!lista;)
  16.                 done;
  17.         done;
  18. !flague
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement