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: 2851

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 agree. Here's the link:
subject: trees
jQuery in Action, 3rd edition