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
null
asparent
, store them as root nodes. -
When a
Node
is created, find all itschildren
and 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?