Results 1 to 3 of 3
  1. #1
    trill is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Tree structure using JAVA

    Hi, Where can I find the example of Tree structure using JAVA ?
    I would like to do a family tree by using Java. but I have no idea.

    Thanks.

  2. #2
    shanePreater is offline Member
    Join Date
    Jul 2007
    Location
    England, Bath
    Posts
    47
    Rep Power
    0

    Default

    You could implement this using a simple class structure:
    Java Code:
    public class Person {
      private List<Person> parents;
      private List<Person> children;
    
      ...
    
      public void addParent(Person parent) {
        this.getParents().add(parent);
        parent.getChildren().add(this);
      }
    
      public void addChild(Person child) {
        this.getChildren().add(child);
        child.getParents().add(this);
      }
    }
    Obviously you will need to implement the getters and setters for the lists but that will allow you to construct your family tree. Also you may wish to limit the parent list to 2 entries or change this for :
    Java Code:
    private Person mother;
    private Person father;
    instead.

    Hope this gets you started. :)

  3. #3
    nagu is offline Member
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

Similar Threads

  1. Binary Tree Implementation in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:35 PM
  2. Stack data structure in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:34 PM
  3. Java Grapical Tree
    By Deo Favente in forum Reviews / Advertising
    Replies: 3
    Last Post: 02-18-2008, 06:12 AM
  4. Java Array of Structure
    By PAffiliates in forum New To Java
    Replies: 1
    Last Post: 01-28-2008, 06:08 AM
  5. Implementing a red-black tree in java
    By baltazar in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 08:37 PM

Posting Permissions

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