p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Java > Java and JDK > Java Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 8th, 2006, 10:32 PM
Authorized User
Points: 50, Level: 1
Points: 50, Level: 1 Points: 50, Level: 1 Points: 50, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2004
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to pandjie
Default tree data structure

I want to create a tree data structure [not binary tree nor JTree] with unlimited branch and I can go in each branch in that tree. Anyone can give me an example? or URL link..

Thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old January 16th, 2006, 05:15 AM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe something like this?

import java.util.*;

public class NaryTree
{
  private ArrayList children = new ArrayList();
  private Object value;

  public NaryTree(Object value)
  {
    this.value = value;
  }

  public NaryTree getChild(int n)
  {
    return (NaryTree)children.get(n);
  }

  public void putChild(int n, NaryTree child)
  {
    children.add(n, child);
  }

  public Object getValue()
  {
    return value;
  }

  public void setValue(Object value)
  {
    this.value = value;
  }
}


Of course, this is basically just an ArrayList with a value associated with it.  So you could just extend ArrayList, add the value getter and setter, and have your N-ary tree.  But the code might be a little harder to understand without some good Javadocs.

Jon Emerson
Adobe Systems, Inc.
http://www.jonemerson.net/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Tree Structure Problem KLam BOOK: Beginning InfoPath 2003 1 August 5th, 2007 12:44 PM
Testing tree structure rjonk XSLT 6 November 16th, 2006 10:11 AM
Need help with tree data structure vidhya_venkat C++ Programming 0 June 14th, 2006 02:13 PM
Creating a Tree Structure pazzuzu C++ Programming 2 February 26th, 2005 12:07 PM
Show data in tree-view structure kiennt Crystal Reports 1 March 1st, 2004 06:21 PM



All times are GMT -4. The time now is 04:11 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc