Help for this page

Select Code to Download


  1. or download this
    my $tree = [ 1
               , [ 2
    ...
                  : $nodefn->( $_, $depth );
        }
    }
    
  2. or download this
    sub count_nodes {
        my $count;
    ...
    
    print count_nodes($tree), $/;
    # 7
    
  3. or download this
    sub print_node {
        my ($leaf, $depth) = @_;
        print "  " x ($depth - 1), "* $leaf", $/;
    }
    
  4. or download this
    traverse( \&print_node, $tree );
    # * 1
    ...
    #       * 5
    #     * 6
    # * 7
    
  5. or download this
    sub bfs_traverse {
        my ($nodefn, $tree, $depth) = @_;
    ...
        bfs_traverse( $nodefn, [map @$_, @branches], $depth )
            if @branches;
    }
    
  6. or download this
    bfs_traverse( \&print_node, $tree );
    # * 1
    ...
    #     * 4
    #     * 6
    #       * 5