Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-01-2007, 05:10 PM
Member
 
Join Date: Jul 2007
Posts: 40
Rep Power: 0
trill is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-02-2007, 03:50 PM
Member
 
Join Date: Jul 2007
Location: England, Bath
Posts: 47
Rep Power: 0
shanePreater is on a distinguished road
Default
You could implement this using a simple class structure:
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 :
Code:
private Person mother;
private Person father;
instead.

Hope this gets you started.
__________________
Shane Preater - The One Vision Group
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary Tree Implementation in Java Java Tip java.lang 0 04-16-2008 11:35 PM
Stack data structure in Java Java Tip java.lang 0 04-16-2008 11:34 PM
Java Grapical Tree Deo Favente Reviews / Advertising 3 02-18-2008 07:12 AM
Java Array of Structure PAffiliates New To Java 1 01-28-2008 07:08 AM
Implementing a red-black tree in java baltazar New To Java 1 07-13-2007 09:37 PM


All times are GMT +2. The time now is 10:59 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org