Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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: 38020
    
  22
Do your nodes not have an isLeaf() mtehod?
 
I agree. Here's the link: http://aspose.com/file-tools
 
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 ??