Fixed critical bugs + DFS now works on all trees
This commit is contained in:
parent
0420af289e
commit
8351fef480
Binary file not shown.
Binary file not shown.
|
@ -399,7 +399,7 @@ let draw_integer x0 y n0 r =
|
||||||
let len = r/3 in
|
let len = r/3 in
|
||||||
let offset = size*(len/2) in
|
let offset = size*(len/2) in
|
||||||
for i = 0 to size do
|
for i = 0 to size do
|
||||||
let x = -(1 - delta size 0)*4 + x0 - offset + i * (len+8) in
|
let x = x0 - (-(1 - delta size 0)*8 - offset + i * (len+8)) in
|
||||||
if Array.mem (!n mod 10) [|0; 4; 5; 6; 7; 8; 9|] then
|
if Array.mem (!n mod 10) [|0; 4; 5; 6; 7; 8; 9|] then
|
||||||
draw_poly_line [|(x-len/2, y+len); (x-len/2, y)|];
|
draw_poly_line [|(x-len/2, y+len); (x-len/2, y)|];
|
||||||
|
|
||||||
|
@ -478,25 +478,38 @@ let even_more_pretty_printing t r ystep skip =
|
||||||
graphdata ;;
|
graphdata ;;
|
||||||
|
|
||||||
|
|
||||||
let generate_full_graph d =
|
let generate_full_tree d =
|
||||||
let rec aux n = match n with
|
let rec aux n = match n with
|
||||||
| 0 -> Leaf (Random.int 99)
|
| 0 -> Leaf (Random.int 1000)
|
||||||
| k -> begin
|
| k -> begin
|
||||||
Node (Random.int 99, aux (n-1), aux (n-1))
|
Node (Random.int 1000, aux (n-1), aux (n-1))
|
||||||
end
|
end
|
||||||
in aux d ;;
|
in aux d ;;
|
||||||
|
|
||||||
|
let generate_some_tree maxd nodechance leafchance =
|
||||||
|
let rec aux n = match n with
|
||||||
|
| 0 -> if (Random.int 101 < leafchance) then Leaf (Random.int 100) else Empty
|
||||||
|
| k -> begin
|
||||||
|
match Random.int 101 with
|
||||||
|
| k when k <= nodechance -> Node (Random.int 1000, aux (n-1), aux (n-1))
|
||||||
|
| k -> if (Random.int 101 < leafchance) then Leaf (Random.int 1000) else Empty
|
||||||
|
end
|
||||||
|
in aux maxd ;;
|
||||||
|
|
||||||
let rec nth l n = match l with
|
let rec nth l n = match l with
|
||||||
| [] -> failwith "Out of range"
|
| [] -> failwith "Out of range"
|
||||||
| h::t when n = 0 -> h
|
| h::t when n = 0 -> h
|
||||||
| h::t -> nth t (n-1) ;;
|
| h::t -> nth t (n-1) ;;
|
||||||
|
|
||||||
let even_more_fancy_dfs_prefixe t graphdata r tts rfound gfound bfound rmark gmark bmark =
|
let even_more_fancy_dfs_prefixe t graphdata r tts rfound gfound bfound rmark gmark bmark =
|
||||||
let rec aux tr dpth os =
|
let d = depth_of_tree t in
|
||||||
|
let count_per_depth = Array.make d 0 in
|
||||||
|
let rec aux tr dpth =
|
||||||
match tr with
|
match tr with
|
||||||
| Empty -> ()
|
| Empty -> ()
|
||||||
| Leaf _ -> begin
|
| Leaf _ -> begin
|
||||||
let data = nth graphdata.(dpth) os in
|
let data = nth graphdata.(dpth) (List.length graphdata.(dpth) - count_per_depth.(dpth) - 1) in
|
||||||
|
count_per_depth.(dpth) <- count_per_depth.(dpth) + 1;
|
||||||
set_color (rgb rfound gfound bfound);
|
set_color (rgb rfound gfound bfound);
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
Unix.sleepf tts;
|
Unix.sleepf tts;
|
||||||
|
@ -504,17 +517,18 @@ let even_more_fancy_dfs_prefixe t graphdata r tts rfound gfound bfound rmark gma
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
end
|
end
|
||||||
| Node (_, g, d) -> begin
|
| Node (_, g, d) -> begin
|
||||||
let data = nth graphdata.(dpth) os in
|
let data = nth graphdata.(dpth) (List.length graphdata.(dpth) - count_per_depth.(dpth) - 1) in
|
||||||
|
count_per_depth.(dpth) <- count_per_depth.(dpth) + 1;
|
||||||
set_color (rgb rfound gfound bfound);
|
set_color (rgb rfound gfound bfound);
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
Unix.sleepf tts;
|
Unix.sleepf tts;
|
||||||
set_color (rgb rmark gmark bmark);
|
set_color (rgb rmark gmark bmark);
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
|
|
||||||
aux g (dpth+1) (2*os);
|
aux g (dpth+1);
|
||||||
aux g (dpth+1) (2*os + 1);
|
aux d (dpth+1);
|
||||||
end
|
end
|
||||||
in aux t 0 0 ;;
|
in aux t 0 ;;
|
||||||
|
|
||||||
|
|
||||||
let even_more_fancy_dfs_infixe t graphdata r tts rfound gfound bfound rmark gmark bmark =
|
let even_more_fancy_dfs_infixe t graphdata r tts rfound gfound bfound rmark gmark bmark =
|
||||||
|
@ -522,7 +536,7 @@ let even_more_fancy_dfs_infixe t graphdata r tts rfound gfound bfound rmark gmar
|
||||||
match tr with
|
match tr with
|
||||||
| Empty -> ()
|
| Empty -> ()
|
||||||
| Leaf _ -> begin
|
| Leaf _ -> begin
|
||||||
let data = nth graphdata.(dpth) os in
|
let data = nth graphdata.(dpth) (List.length graphdata.(dpth) - os - 1) in
|
||||||
set_color (rgb rfound gfound bfound);
|
set_color (rgb rfound gfound bfound);
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
Unix.sleepf tts;
|
Unix.sleepf tts;
|
||||||
|
@ -532,13 +546,14 @@ let even_more_fancy_dfs_infixe t graphdata r tts rfound gfound bfound rmark gmar
|
||||||
| Node (_, g, d) -> begin
|
| Node (_, g, d) -> begin
|
||||||
aux g (dpth+1) (2*os);
|
aux g (dpth+1) (2*os);
|
||||||
|
|
||||||
let data = nth graphdata.(dpth) os in
|
let data = nth graphdata.(dpth) (List.length graphdata.(dpth) - os - 1) in
|
||||||
set_color (rgb rfound gfound bfound);
|
set_color (rgb rfound gfound bfound);
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
Unix.sleepf tts;
|
Unix.sleepf tts;
|
||||||
set_color (rgb rmark gmark bmark);
|
set_color (rgb rmark gmark bmark);
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
aux g (dpth+1) (2*os + 1);
|
|
||||||
|
aux d (dpth+1) (2*os + 1);
|
||||||
end
|
end
|
||||||
in aux t 0 0 ;;
|
in aux t 0 0 ;;
|
||||||
|
|
||||||
|
@ -548,7 +563,7 @@ let even_more_fancy_dfs_postfixe t graphdata r tts rfound gfound bfound rmark gm
|
||||||
match tr with
|
match tr with
|
||||||
| Empty -> ()
|
| Empty -> ()
|
||||||
| Leaf _ -> begin
|
| Leaf _ -> begin
|
||||||
let data = nth graphdata.(dpth) os in
|
let data = nth graphdata.(dpth) (List.length graphdata.(dpth) - os - 1) in
|
||||||
set_color (rgb rfound gfound bfound);
|
set_color (rgb rfound gfound bfound);
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
Unix.sleepf tts;
|
Unix.sleepf tts;
|
||||||
|
@ -557,9 +572,9 @@ let even_more_fancy_dfs_postfixe t graphdata r tts rfound gfound bfound rmark gm
|
||||||
end
|
end
|
||||||
| Node (_, g, d) -> begin
|
| Node (_, g, d) -> begin
|
||||||
aux g (dpth+1) (2*os);
|
aux g (dpth+1) (2*os);
|
||||||
aux g (dpth+1) (2*os + 1);
|
aux d (dpth+1) (2*os + 1);
|
||||||
|
|
||||||
let data = nth graphdata.(dpth) os in
|
let data = nth graphdata.(dpth) (List.length graphdata.(dpth) - os - 1) in
|
||||||
set_color (rgb rfound gfound bfound);
|
set_color (rgb rfound gfound bfound);
|
||||||
draw_circle (fst (snd data)) (snd (snd data)) r;
|
draw_circle (fst (snd data)) (snd (snd data)) r;
|
||||||
Unix.sleepf tts;
|
Unix.sleepf tts;
|
||||||
|
@ -574,9 +589,11 @@ Random.self_init ;;
|
||||||
open_graph " 1800x800" ;;
|
open_graph " 1800x800" ;;
|
||||||
set_window_title "Trees" ;;
|
set_window_title "Trees" ;;
|
||||||
|
|
||||||
let gdata = even_more_pretty_printing (generate_full_graph 4) 40 150 false ;;
|
let tt = generate_some_tree 4 100 75 ;;
|
||||||
|
|
||||||
even_more_fancy_dfs_prefixe (generate_full_graph 4) gdata 40 0.2 255 255 32 32 32 255 ;;
|
let gdata = even_more_pretty_printing tt 40 150 false ;;
|
||||||
|
|
||||||
|
even_more_fancy_dfs_prefixe tt gdata 40 0.2 255 255 32 32 32 255 ;;
|
||||||
|
|
||||||
close_graph () ;;
|
close_graph () ;;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue