Java tree problem!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rameshraj
    New Member
    • Jul 2007
    • 4

    Java tree problem!

    I need a source code that implements the simple tree approach but each node can adjust for more than 2 childs.Is it possilbe or yet another option available.
    Plz provide the module or source code.
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by rameshraj
    I need a source code that implements the simple tree approach but each node can adjust for more than 2 childs.Is it possilbe or yet another option available.
    Plz provide the module or source code.
    You mean the programming concept of a tree instead of a graphical tree? Check the class TreeList from apache or write your own tree.

    If you want to write your own tree, think about what the concept of a tree is. You can have a class Node which is a container class for some data (Strings, Integers, other Objects...) plus it has a Collection (Vector, Array, List, ...) of children (also nodes). It must have a "addChild" method and a "getChild" method, maybe a "search" method or similar,... Depends on what you want.

    Try writing it and if you need help, ask here! :-)
    Hope that helps.

    Greetings,
    Nepomuk

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by rameshraj
      I need a source code that implements the simple tree approach but each node can adjust for more than 2 childs.Is it possilbe or yet another option available.
      Plz provide the module or source code.
      Nope, we're not going to give you any source code (you want the code so why
      should we build it?). An extremely simple implementation for a general tree node
      could be this:

      [code=java]
      public class Node {
      private Node child; // ref to first child
      private Node sibling; // ref to next sibling
      private Node parent; // ref to parent;
      }
      [/code]

      All childs of a node can be reached first through the leftmost child reference
      and next through the sibling list of that child. The parent reference is optional
      but very handy to have.

      kind regards,

      Jos

      Comment

      Working...