Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding the leaf nodes in a tree data structure

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would try recursion.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do your nodes not have an isLeaf() mtehod?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic