I am trying to convert a BinaryTree which is made of Nodes into a JTree for a GUI view. I figure this is the pseudo-code I need:
if root == null
set data as root
if data < root
if leftNode == null
add data to left node
if data < leftNode
add data to left node
if data > leftNode
add data to right node
if data > root
if rightNode == null
add data to right node
if data < right node
add data to left node
if data > right node
add data to right node
Any ideas on how to actually implement this pseudo code? I know there needs to be some recursion to get this to affect all the child nodes.
Instead of traversing your tree, implement the
TreeModelinterface so that it fetches the tree’s nodes as requested by theJTree. Examples may be found in Creating a Data Model.Addendum:
FileSystemModelis a related example.