Create a class for Node, with a set of children, which are nodes as well, store the root Node(s). Implement method for insertion. Then implement the following algorithm:
-
Find the elements, having
nullasparent, store them as root nodes. -
When a
Nodeis created, find all itschildrenand create them aschildren.
(Note, that whenever you add a child a Node was created).
Implement the display method, which traverses the tree in depth-first fashion and display each element as you like.
2
solved How to display a two dimensional array as a hierarchy table in java?