Here's the question: does anyone know of a generic "Tree" class
that can do depth-first/breadth-first traversals (i.e. return a
collection of nodes sorted in that order?) Seems like very rudimentary
stuff, yet I don't see anything in the JDK 1.3 docs that is applicable,
nor do my net searches (via Google - alas, these guys bought DejaNews
and decided not to maintain the site until they could provide equivalent
service!) reveal anything. The things I did find:
- java.util.TreeMap and java.util.TreeSet
but they keep things sorted by a key and, thus, don't allow you to
manually create the tree (e.g. do something like
Tree.add(Object parent))
- javax.swing.JTree
Seems to have what I want, but it's embedded in the Swing library
to which most browsers don't have access (unless Plugin installed).
- JDSL from Brown (Boston?) University
Has exactly what I want, but doesn't allow people to use it
commercially :-(
Does anyone know of any other public domain alternatives? Or do I have
to roll my own?
Thanks in advance,
Tom (tw...@integrasolv.com)
This is the only one I know of personally. :( Only other thing I could think
of would be to write your own, which wouldn't necessarily be a fun thing to
do. Maybe someone else will have an answer for you.
> Here's the question: does anyone know of a generic "Tree" class
> that can do depth-first/breadth-first traversals (i.e. return a
> collection of nodes sorted in that order?) Seems like very rudimentary
> stuff, yet I don't see anything in the JDK 1.3 docs that is applicable,
> nor do my net searches (via Google - alas, these guys bought DejaNews
> and decided not to maintain the site until they could provide equivalent
> service!) reveal anything.
I had to create a generic tree class for my Honours project, which did
allow for fairly generic (recursive) manipulation. Feel free to
download it and butcher it at your leisure.
- http://www.roesti.f2s.com/programming/_source/org/roesti/util/Tree.java
The complete code for the project is available here:
- http://www.roesti.f2s.com/programming/deolitow/source.xhtml
I made the code I wrote for Honours available under the GPL, so if
you're using my code for other non-commercial software, you're generally
in the clear. Email me if you have any questions (or if you want to
pinch other stuff).
> - javax.swing.JTree
> Seems to have what I want, but it's embedded in the Swing library
> to which most browsers don't have access (unless Plugin installed).
JTree is a good control for displaying tree structures in a list box,
but I don't know of a good non-Swing equivalent. I have not tried to
use my Tree class with this component, either.
HTH,
Aaron Nielsen
roe...@f2s.com