Wednesday, January 1, 2003 06:11 AM
Unfortunately, java has not done much in the way of Data Structures for the type of Tree you are looking for in the Collections API's. They have implemented TreeSet and TreeMap, but those are binary (red-black) trees.
I guess by "uncle" you mean elements on the same "tree level". This is not really that hard if you understand the "breadth first search" algorithms in tree structures. I once adapted it for nodes with multiple children (for a Graph Data Structure). What I would look at is instead of placing the nodes in a Vector, look at the methods in the javax.swing.tree.DefaultTreeModel API's for creating the tree. Since you want to display the tree visually, this puts you half way there using the javax.swing.tree.* classes.
As you add elements to the tree, you would look for the parent to add the node to the tree. A breadth first traversal of the tree would allow you to find "uncles" since you keep all the nodes on the same level in a Queue.
For online discussions of Data Structures check out the link provided.
Hope this helps; and gives you some direction. What you are doing is not a trivial problem, but it is fun and rewarding.