This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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: 43986
    
  33
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
 
It's not a secret anymore!