I am trying to print a tree with the help of "format" and a variables. But couldn't figure out how to pass in variable and get an output in a generalized form. The below code works for a particular example but not for any tree.
I used hard coded approach for getting the horizontal spacing right using the if statement as below. But i want to just pass-in the variable "count" which contains the height of the tree, and get a output directly.
if (count .eq. 9) then
write(6,9) t%element
9 format (t12,I3)
else if (count .eq. 8) then
write(6,8) t%element
8 format (t9,I3)
else if (count .eq. 7) then
write(6,7) t%element
7 format (t6,I3)
else
write(6,6) t%element
6 format (t3,I3)
end if
The result you get is like this
1
2
3
4
5
6
7