diff --git a/src/findpath.ml b/src/findpath.ml index 90b07d5..d96b994 100644 --- a/src/findpath.ml +++ b/src/findpath.ml @@ -32,4 +32,12 @@ let find_path (gr: 'a graph) (begin_node: id) (end_node: id) (filter: 'a arc -> try find_way begin_node [begin_node] with - | Not_found -> []; + | Not_found -> [] + +let path_to_list s = + let numbers = List.map int_of_string (String.split_on_char ' ' s) in + let rec build_pairs = function + | x :: (y :: _ as rest) -> (x, y) :: build_pairs rest + | _ -> [] + in + build_pairs numbers \ No newline at end of file diff --git a/src/findpath.mli b/src/findpath.mli index ce1ca5e..14633e8 100644 --- a/src/findpath.mli +++ b/src/findpath.mli @@ -4,4 +4,7 @@ open Graph val child_nodes: 'a graph -> id -> id list (* search path between 2 node and return the path : a list of node *) -val find_path: 'a graph -> id -> id -> ('a arc -> bool) -> id list \ No newline at end of file +val find_path: 'a graph -> id -> id -> ('a arc -> bool) -> id list + +(* for example take [1;0;2;4] into [(1,0);(0,2);(2,4)]*) +val path_to_list: string -> (int * int) list \ No newline at end of file