Dynamically Generated Tree Listing
A list exists as follows...
I am trying to make a simple tree-like menu similar to DMOZ and others. This list
is a *very small* subset of the actual number of catagories that exist. But
it should be sufficient to explain it. :)
Take the output example of
Now the list would not want to put Washington or Florida on the
same side as California in order to keep the vertical line number
to a minimum. There will be at most two columns.
So the question is, given a tree that extends to some rediculous
extents and given any parent as a starting point, what would be
an efficient way of
1) Checking how many layers deep it could display to
be less then a maximum number of vertical lines (MAXN)
and
2) Which order it would need to display all the items, in order
to minimize the vertical space usage.
I'm in c++ but I'm not sure the language really matters... >;-)
thanks for any ideas
-eurijk! >;-)
+----+--------+---------------+
| id | parent | title |
+----+--------+---------------+
| 1 | 0 | Washington |
| 2 | 0 | California |
| 3 | 0 | Florida |
| 4 | 1 | Seattle |
| 5 | 1 | Tacoma |
| 6 | 2 | San Francisco |
| 7 | 2 | Los Angeles |
| 8 | 2 | Oakland |
| 9 | 2 | Sacramento |
| 10 | 2 | Los Gatos |
| 11 | 2 | Annahiem |
| 12 | 3 | Miami |
| 13 | 4 | Redmond |
| 14 | 4 | Bellevue |
| 15 | 4 | Kent |
| 16 | 4 | Aurora |
+----+--------+---------------+
I am trying to make a simple tree-like menu similar to DMOZ and others. This list
is a *very small* subset of the actual number of catagories that exist. But
it should be sufficient to explain it. :)
Take the output example of
Countries => USA => Cool States =>
Washington (2) California (6)
Seattle (4) San Francisco
Redmond Los Angeles
Bellevue Oakland
Kent Sacramento
Aurora Los Gatos
Florida (1) Annahiem (sp?)
Miami
Now the list would not want to put Washington or Florida on the
same side as California in order to keep the vertical line number
to a minimum. There will be at most two columns.
So the question is, given a tree that extends to some rediculous
extents and given any parent as a starting point, what would be
an efficient way of
1) Checking how many layers deep it could display to
be less then a maximum number of vertical lines (MAXN)
and
2) Which order it would need to display all the items, in order
to minimize the vertical space usage.
I'm in c++ but I'm not sure the language really matters... >;-)
thanks for any ideas
-eurijk! >;-)
