jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Finding the leaf nodes in a tree data structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Finding the leaf nodes in a tree data structure" Watch "Finding the leaf nodes in a tree data structure" New topic
Author

Finding the leaf nodes in a tree data structure

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

How do I go about finding all the leaf nodes in a Tree data structure? My way would be to use a LinkedList and find all the nodes for which nextNode value is null. Is there a data structure that is specifically designed for this sort of thing?


~ Mansukh
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I would try recursion.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37890
    
  22
Do your nodes not have an isLeaf() mtehod?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Finding the leaf nodes in a tree data structure
 
Similar Threads
JTree reload question, AGAIN
JTree flicker
how can I change this tree with different Icons for Different nodes at Run Time
Help me in choosing a pattern
tree not getting updated on Linux ??