Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Traverse a tree?
Mike Coppola
Greenhorn
Posts: 1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Does anyone have an example of an algorithm to traverse a tree?
Paul Clapham
Marshal
Posts: 28193
95
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Mike, welcome to the Ranch!
There are plenty of tree-traversal algorithms out there. However if you're looking for one which you can apply to your code, it would help if we knew how you implemented your tree. Care to provide some more details?
Steve Fahlbusch
Bartender
Posts: 612
7
I like...
posted 9 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Sure ----
traverse ( Node subtree ) { if subtree = null return traverse ( subtree.left ) do_something_with_data ( subtree.data ) traverse ( subtree.right )
just if you google there are many, many examples out there.
Campbell Ritchie
Marshal
Posts: 79180
377
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You should
also find about depth‑first and breadth‑first traversals. They work differently.
permaculture is giving a gift to your future self. After reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Employee Class problem
Binary search tree
Recursively Set Tester in a Recursive Tree
Tree Traversal
Creating a tree nodes
More...