in reply to GRAPH is too complicated for my needs.
in thread Print all possible paths in a graph and some graph creation too!
Then again, I have written an AVL tree implementation in FORTRAN, so I shouldn't talk too much about doing things the hard way.
I'd implement something like this:
The printing code will be similar, but you'll instead pass a string down the recursive call tree, adding level names until you run out of levels, then printing it. The recursion plus the loop will automatically follow all paths for you.Create root-node hash Current level is zero Establish limits: max & min nodes per level, number of levels root{A0} = add_levels($current_level, $level_limit, $min_nodes, $max_n +odes); sub add_levels { return if current level is > the limit, bump it if not calculate a random number between high and low limit new_level = {}; for $n (0..$local_limit) { generate $name from level and $n new_level{$name} = add_levels($current_level, $limit, $min, $max +) } return $new_level; }
I have written a program to do this but I'm not posting it; you'll learn a lot more if you follow this outline and write it yourself; as you don't want to handwave the details via Graph, I assume there's a reason for writing it yourself -- and me writing it for you won't teach you anywhere near as much.
I recommend running under the debugger, as you'll be able to x the growing data structure as you go along and see if it's working.
|
|---|