-
February 6th, 2003, 09:38 AM
#1
Junior Member
Implementing Trees in JAVA
hi everyone out there,
I'm in dire need of some help, and I really need it asap....
Is there any built-in 'tree' data-structure in JAVA or do I have to implement one myself..???
Any sort of help is welcome..
bye
NULTRAX
-
February 6th, 2003, 10:33 AM
#2
Member
NULTRAX,
Doubt it. I had to do the same thing about two weeks ago for a coursework, which is what I assume yours is for...... Mmmmm.
Ok, a hint. You will need to create a class called BinarySearchTreeNode that looks something like:
public class BinarySearchTreeNode {
BinarySearchTreeNode left;
BinarySearchTreeNode right;
Object theDataObject;
public BinarySearchTreeNode (Object theDataObject) {
this.left = null;
this.right = null;
this.theDataObject = theDataObject;
}
}
You then need to think about how you will create the Insert method, which isn't too hard. The difficult part comes when you have to remove nodes from the tree.
<goodAdvice> If you use the above, then you MUST quote your source (not me, just say Antionline and give the address). It's good practice and prevents you being accussed of plagerism. </goodAdvice>
Good luck.
Regards,
T6286
-
February 6th, 2003, 05:11 PM
#3
I'd also suggest keeping a reference to the parent node as well. This can simplify the code alot when checking to see if a Node is on the left or right, or finding the sibling of a Node. These two methods are very helpful for the different types of tree traversals.
\"When you say best friends, it means friends forever\" Brand New
\"Best friends means I pulled the trigger
Best friends means you get what you deserve\" Taking Back Sunday
Visit alastairgrant.ca
-
February 7th, 2003, 06:10 AM
#4
Junior Member
hi..
Guess it's too bad, there isn't anything built-in..
It's OK, I can make my custom-made data-structure, I was just hoping I would be spared of all that unnecessary work...just looking out for some shortcuts..
Thanks a lot
NulTraX
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|