Data Stucture Storing Help !!

Hi,

I have structure like

level 0

level 1

-level 2

-level 2

level 1

-level 2

-level 2

level 0

level 1

-level 2

-level 2

level 1

-level 2

-level 2

I'm thinking of using a mix of ArrayList and HashMap to store the data.

Any suggestions ?

[347 byte] By [hemalpatela] at [2007-11-27 1:42:48]
# 1
for such thing (which looks like a tree), i would rather use a JTree
calvino_inda at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 2
HeyFor something like this i also should use a Jtree.Here is a small example http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JTree.htmlSatanduvel
Satanduvela at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi,I'm in an idea that jtree is a swing class, while i'm using core java. I dont have graphics or visualizations. Can i still use jtree ? or there is an equivalent of this in core java classes ?
hemalpatela at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 4
... or XML ...
J@A@V@Aa at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 5

Isn't it just a structure like this? [root]

/\

level 0:[][]

/\/\

level 1: [] [] [] []

/\ /\ /\ /\

level 2: [][][][][][][][]

If so, you need to implement a binary tree:

class BinaryTree {

Node root;

// ... more BinaryTree attributes / methods ...

}

class Node {

Node left;

Node right;

// ... more Node attributes / methods ...

}

prometheuzza at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 6
or XML
J@A@V@Aa at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 7

And if you had more than two child nodes:

class NTree {

Vector<Node>rootNodes;

// ...

}

class Node {

Vector<Node>childNodes;

// ...

}

Jack

jack@square6a at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 8
Hi,Means there is no inbuilt java functionality to support this ?Can you give a somebody point to a code example to show how hierarchy is implemented ?
hemalpatela at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 9

> Hi,

>

> Means there is no inbuilt java functionality to

> support this ?

That is correct.

> Can you give a somebody point to a code example to

> show how hierarchy is implemented ?

I already did. The Tree holds one root, which is a Node. That Node can have two children: a left- and a right child. Those children themselves can have two children of their own, etc...

prometheuzza at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...
# 10

You can very simple use xml:

<root>

<level0>

<level1>

<level2></level2>

<lelve2></level2>

</level1>

</level0>

</root>

And than you can use SAX or DOM model.

You can build the xml simply:

StringBuffer s=new StringBuffer(2500);

s.append("<root>").append("<level0>").append(....).....append("</root>");

J@A@V@Aa at 2007-7-12 0:59:54 > top of Java-index,Java Essentials,Java Programming...