aspose file tools*
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 Spring in Action this week in the Spring 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: 39415
    
  28
Do your nodes not have an isLeaf() mtehod?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Finding the leaf nodes in a tree data structure