in reply to program that counts all the vertices in a given tree
o_O:
Your vertices function is printing the number of arguments you gave it: The @_ variable is the list of arguments passed to your subroutine. Since you pass it $root, you'll always get 1 for the result.
You either need to expand the tree into the list of vertices and pass that list to the vertices subroutine, or have the vertices subroutine traverse the tree and keep count.
You haven't shown the code for the XX_order subroutines, but based on the rest of your code, you could simply replace the print statement with an increment to get the vertex count.
Show a bit more of your code and we can give you a little more help.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: program that counts all the vertices in a given tree
by o_0 (Initiate) on Jul 01, 2013 at 01:42 UTC | |
by o_0 (Initiate) on Jul 01, 2013 at 02:36 UTC | |
by Anonymous Monk on Jul 01, 2013 at 03:00 UTC |