#!/usr/bin/perl /usr/bin/asp-perl <% my $count; my $winner = { value => 'wwabwcd', left => { value => 'wab', left => { value => 'a'}, right => { value => 'b'}}, right => { value => 'wcd', left => { value => 'c', left => { value => 'X'}}, right => { value => 'd'}}}; my $loser = { value => 'second', left => { value => 'wlablcd', left => { value => 'lab'}, right => { value => 'lcd'}}, right => { value => 'lwabwcd'}}; my $brock = { value => 'Me', left => { value => 'Russle Brock Wilcox Sr', left => { value => "Russle Eugene Wilcox"}, right => { value => "Letha Wilcox"}}, right => { value => 'Kandy Kay Rosson', left => { value => 'Joseph Rosson'}, right => { value => 'Kay Rosson'}}}; $childnum = 0; sub build_tree { my ($depth) = @_; if($depth == 0) { return {value => $childnum++}; } return { left => build_tree($depth - 1), right => build_tree($depth - 1), value => $childnum++}; } my $hrm = build_tree(4); sub tree_depth { my ($node) = @_; my $depth = 0; if($node->{left}) { $depth = tree_depth($node->{left}); } if($node->{right}) { my $right_depth = tree_depth($node->{right}); $depth = $right_depth if ($right_depth > $depth); } return 1 + $depth; } sub draw_tree { my ($node, $depth, $tree_depth, $side, @lines) = @_; my $child_depth = $tree_depth - $depth; if($node->{left}) { my @left_lines = @lines; if($side eq 'right') { push @left_lines, $depth; } draw_tree($node->{left}, $depth+1, $tree_depth, 'left', @left_lines); } print "\n"; for my $col (1 .. $child_depth) { print "\n"; } print "{left}) {print " border-left: 1px solid black;"}; print "\" align=center>$node->{value}\n"; my @show_lines = @lines; if ($side eq 'right') { push @show_lines, $depth; } for my $col (1 .. $depth) { if($depth - $col + 1 == $show_lines[-1]) { pop @show_lines; print " \n"; } else { print "\n"; } } print "\n"; if($node->{right}) { my @right_lines= @lines; if($side eq 'left') { push @right_lines, $depth; } draw_tree($node->{right}, $depth+1, $tree_depth, 'right', @right_lines); } return $child_depth + 1; } %>
<% draw_tree($hrm, 0, tree_depth($hrm), ''); %> <% draw_tree($loser, 0, tree_depth($hrm), ''); %>