feat: path_to_list

This commit is contained in:
Baptiste 2024-12-02 16:46:19 +01:00
parent 89139ffe3c
commit bc89f7bcf5
2 changed files with 13 additions and 2 deletions

View file

@ -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

View file

@ -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
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