Results 1 to 4 of 4

Thread: Implementing Trees in JAVA

  1. #1
    Junior Member
    Join Date
    Jan 2003

    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..


  2. #2
    Join Date
    Nov 2001

    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.



  3. #3
    Senior Member
    Join Date
    Nov 2002
    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

  4. #4
    Junior Member
    Join Date
    Jan 2003

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts