Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Graph.Pack.Digraph;;
- let read_graph filename =
- let string_of_char = String.make 1 in
- let read_int in_ch =
- let is_valid ch = ch >= '0' && ch <= '9' in
- let ioc ch = (int_of_char ch)-(int_of_char '0') in
- let res = ref 0 in
- let tmp = ref '0' in
- try
- while true do
- tmp := (input_char in_ch);
- if (is_valid !tmp) then
- begin
- res := !res * 10 + (ioc !tmp);
- end
- else
- raise Exit;
- done;
- !res;
- with
- Exit -> !res; in
- let in_ch = open_in filename in
- let nb_of_vertex = read_int in_ch in
- let arr_of_vertex = Array.make nb_of_vertex (V.create 0) in
- let graph = create () in
- begin
- for i=0 to (nb_of_vertex-1) do
- arr_of_vertex.(i)<-(V.create i);
- add_vertex graph arr_of_vertex.(i);
- done;
- end;
- try
- while true do
- let f1 = read_int in_ch in
- let f2 = read_int in_ch in
- add_edge graph (arr_of_vertex.(f1)) (arr_of_vertex.(f2));
- done;
- graph;
- with
- End_of_file -> graph;
- ;;
- let _ = display_with_gv (read_graph "blog.txt");;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement