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 Java in General and the fly likes trees Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "trees" Watch "trees" New topic


Higgledy Smith
Ranch Hand

Joined: Mar 07, 2006
Posts: 192
I am trying to understand how to program a solution in trees. Somehow my gets lost between tree theory and applying that theory in code.

Does anyone have (or know a site) to a tree problem that I can use to learn programming trees, preferably a Java solution?

Jeff Verdegan

Joined: Jan 03, 2004
Posts: 6109

I would start by googling for java tree sample code. (Note: When I tried it, the first site that came up was roseindia. Avoid that site. It's riddled with errors.)
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2800

What particular tree are you trying to program?

There are many types of trees in programming, I am assuming that you are talking of a plain old binary tree.
I was thinking of the program and recalled the days when I was learning data structures for the first time
Its fun.
To start with, a tree node looks something like the following code.

Constructing tree is not much tricky as tree traversal is ;).

P.S The above quick code is inspired from my C/C++ way of doing it. There can be better way of doing it in Java.

|Asking Good Questions|
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: trees
It's not a secret anymore!